Multidevice hinzugefügt

This commit is contained in:
Patrick Schindelmann 2019-10-22 11:12:16 +02:00
parent 5e2e85d481
commit 7c86451e5f

View File

@ -63,7 +63,7 @@ function ParameterEvaluation(){
case "$1" in case "$1" in
"-d"|"--device") "-d"|"--device")
shift; # The arg is next in position args shift; # The arg is next in position args
DEVICE="$1" DEVICES+=("$1")
;; ;;
"--celsius") "--celsius")
UNIT="c" UNIT="c"
@ -115,7 +115,10 @@ ParameterEvaluation "$0" "$@"
#Debug #Debug
#echo -e "WARNING:\t\"$WARNING\"" #echo -e "WARNING:\t\"$WARNING\""
#echo -e "CRITICAL:\t\"$CRITICAL\"" #echo -e "CRITICAL:\t\"$CRITICAL\""
#echo -e "DEVICE:\t\t\"$DEVICE\"" #for device in ${DEVICES[@]}
#do
# echo -e "device: \"$device\""
#done
#echo -e "HELP\t\t\"$HELP\"" #echo -e "HELP\t\t\"$HELP\""
#echo -e "PERFDATA\t\t\"$PERFDATA\"" #echo -e "PERFDATA\t\t\"$PERFDATA\""
#echo -e "Alle Args:\t\"$@\"" #echo -e "Alle Args:\t\"$@\""
@ -128,70 +131,118 @@ then
fi fi
#Check, if device is a block-device #Check, if device is a block-device
if [ ! -b "$DEVICE" ] for device in ${DEVICES[@]}
do
if [ ! -b "$device" ]
then
echo "Device $device does not exist or is not a block-Device"
exitvar=1
fi
done
if [ "$exitvar" = "1" ]
then then
echo "Device $DEVICE does not exist or is not a block-Device"
exit 1 exit 1
fi fi
if [ "$UNIT" = "c" ]
then
RESULT=$($HDDTEMP --unit=C $DEVICE)
elif [ "$UNIT" = "f" ]
then
RESULT=$($HDDTEMP --unit=F $DEVICE)
fi
OUTDEV=$(echo "$RESULT" | awk -F: '{print $1}') for device in ${DEVICES[@]}
OUTMODEL=$(echo "$RESULT" | awk -F: '{print $2}' | tr -cd '[:print:]') do
OUTTEMP=$(echo "$RESULT" | awk -F: '{print $3}') if [ "$UNIT" = "c" ]
OUTTEMPCLEAN=$(echo "$OUTTEMP" | tr -dc '0-9') then
RESULT=$($HDDTEMP --unit=C $device)
elif [ "$UNIT" = "f" ]
then
RESULT=$($HDDTEMP --unit=F $device)
fi
OUTDEV=$(echo "$RESULT" | awk -F: '{print $1}')
OUTMODEL=$(echo "$RESULT" | awk -F: '{print $2}' | tr -cd '[:print:]')
OUTTEMP=$(echo "$RESULT" | awk -F: '{print $3}')
OUTTEMPCLEAN=$(echo "$OUTTEMP" | tr -dc '0-9')
#Debug
#echo -e "OUTDEV:\t$OUTDEV"
#echo -e "OUTDEVmodel:\t$OUTDEVmodel"
#echo -e "OUTTEMP:\t$OUTTEMP"
#echo -e "OUTTEMPCLEAN:\t$OUTTEMPCLEAN"
#Erstellen des Perfdata-Results
if [ -n "$PERFDATA" ]
then
#perfdata: temperatur=<temperatur>;<warn>;<crit>
PERFRESULT+=" $(echo "$OUTDEV" | awk -F "/" '{print $NF}')=$OUTTEMPCLEAN;$WARNING;$CRITICAL"
fi
#initialisierung der Varible
exitausgabe="0"
#Auswertung der Temperaturen
if [ "$OUTTEMPCLEAN" -lt "$WARNING" ]
then
# OK - Status
ausgabe+="$OUTMODEL on $OUTDEV is $OUTTEMP "
if [ "$exitausgabe" -gt "0" ]
then
echo do nothing
else
exitausgabe="0"
fi
elif [ "$OUTTEMPCLEAN" -ge "$WARNING" ] && [ "$OUTTEMPCLEAN" -lt "$CRITICAL" ]
then
# WARNING - Status
ausgabe+="$OUTMODEL on $OUTDEV is $OUTTEMP "
if [ "$exitausgabe" -gt "1" ]
then
echo do nothing
else
exitausgabe="1"
fi
elif [ "$OUTTEMPCLEAN" -ge "$CRITICAL" ]
then
#CRITICAL - Status
ausgabe+="$OUTMODEL on $OUTDEV is $OUTTEMP "
if [ "$exitausgabe" -gt "2" ]
then
echo do nothing
else
exitausgabe="2"
fi
else
#UNKNOWN - Status
ausgabe+="$OUTMODEL on $OUTDEV is $OUTTEMP "
if [ "$exitausgabe" -gt "3" ]
then
echo do nothing
else
exitausgabe="3"
fi
fi
done
#Debug #Debug
#echo -e "OUTDEV:\t$OUTDEV" #echo -e "Ausgabe:\t$ausgabe"
#echo -e "OUTDEVmodel:\t$OUTDEVmodel" #echo -e "PERFRESULT:\t$PERFRESULT"
#echo -e "OUTTEMP:\t$OUTTEMP" #echo -e "exitausgbe:\t$exitausgabe"
#echo -e "OUTTEMPCLEAN:\t$OUTTEMPCLEAN"
#Erstellen des Perfdata-Results case $exitausgabe in
if [ -n "$PERFDATA" ] "0")
then echo -e "OK - $ausgabe |$PERFRESULT"
#perfdata: temperatur=<temperatur>;<warn>;<crit>
PERFRESULT="| $(echo "$OUTDEV" | awk -F "/" '{print $NF}')=$OUTTEMPCLEAN;$WARNING;$CRITICAL"
fi
#Auswertung der Temperaturen
if [ "$OUTTEMPCLEAN" -lt "$WARNING" ]
then
echo "OK - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT"
exit 0 exit 0
elif [ "$OUTTEMPCLEAN" -ge "$WARNING" ] && [ "$OUTTEMPCLEAN" -lt "$CRITICAL" ] ;;
then "1")
echo "WARNING - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT" echo -e "WARNING - $ausgabe |$PERFRESULT"
exit 1 exit 1
elif [ "$OUTTEMPCLEAN" -ge "$CRITICAL" ] ;;
then "2")
echo "CRITICAL - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT" echo -e "CRITICAL - $ausgabe |$PERFRESULT"
exit 2 exit 2
else ;;
echo "UNKNOWN - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT" "3")
echo -e "UNKNOWN - $ausgabe |$PERFRESULT"
exit 3
;;
*)
echo -e "UNKNOWN - Error"
exit 3 exit 3
fi
esac
if [ -z "$WARNING" ] && [ -z "$CRITICAL" ]
then
#Debug
echo "WARNING and CRITICAL are zero"
echo "OK - $OUTMODEL on $OUTDEV is $OUTTEMP"
exit 0
elif [ -n "$WARNING" ] && [ -n "$CRITICAL" ]]
then
#Debug
echo "WARNING is non-zero and CRITICAL is non-zero"
echo
fi