icinga-check "check_hddtemp.sh" erstellt
This commit is contained in:
parent
3cc5e3d170
commit
4c0d63ee7f
154
checks/check_hddtemp.sh
Executable file
154
checks/check_hddtemp.sh
Executable file
@ -0,0 +1,154 @@
|
||||
#!/bin/bash
|
||||
|
||||
HDDTEMP="/usr/sbin/hddtemp"
|
||||
PARAMETER="$*"
|
||||
WARNING="40"
|
||||
CRITICAL="50"
|
||||
|
||||
function hilfetext(){
|
||||
cat <<- EOF
|
||||
|
||||
$(basename "$0") [OPTION...]
|
||||
Options:
|
||||
-d | --device
|
||||
-w | --warning (default: 40)
|
||||
-c | --critical (default: 50)
|
||||
-p | --perfdata
|
||||
-h | --help
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
function ParameterEvaluation(){
|
||||
|
||||
options=$(getopt -o c:d:hpw: --long critical: --long device: --long help --long perfdata --long warning: -- "$@")
|
||||
|
||||
#Option nicht verfügbar
|
||||
[ "$?" -eq "0" ] || {
|
||||
echo "Incorrect option provided"
|
||||
exit 1
|
||||
}
|
||||
|
||||
eval set -- "$options"
|
||||
while true; do
|
||||
case "$1" in
|
||||
"-d"|"--device")
|
||||
shift; # The arg is next in position args
|
||||
DEVICE="$1"
|
||||
;;
|
||||
"-w"|"--warning")
|
||||
shift; # The arg is next in position args
|
||||
WARNING="$1"
|
||||
;;
|
||||
"-c"|"--critical")
|
||||
shift; # The arg is next in position args
|
||||
CRITICAL="$1"
|
||||
;;
|
||||
"-p"|"--perfdata")
|
||||
PERFDATA="1"
|
||||
;;
|
||||
"-h"|"--help")
|
||||
hilfetext
|
||||
exit 0
|
||||
;;
|
||||
|
||||
"--")
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
#Prüfen, ob hddtemp installiert ist
|
||||
if [ ! -x "$HDDTEMP" ]
|
||||
then
|
||||
echo "hddtemp nicht gefunden"
|
||||
fi
|
||||
|
||||
#Wenn keine Option oder Argument angegeben wurde, wird die Hilfe ausgegeben
|
||||
if [ -z "$PARAMETER" ]
|
||||
then
|
||||
hilfetext
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ParameterEvaluation "$0" "$@"
|
||||
|
||||
#Debug
|
||||
#echo -e "WARNING:\t\"$WARNING\""
|
||||
#echo -e "CRITICAL:\t\"$CRITICAL\""
|
||||
#echo -e "DEVICE:\t\t\"$DEVICE\""
|
||||
#echo -e "HELP\t\t\"$HELP\""
|
||||
#echo -e "PERFDATA\t\t\"$PERFDATA\""
|
||||
#echo -e "Alle Args:\t\"$@\""
|
||||
|
||||
#Check, if WARNING under CRITICAL
|
||||
if [ "$WARNING" -ge "$CRITICAL" ]
|
||||
then
|
||||
echo "WARNING must be lower then CRITICAL (WARNING=$WARNING;CRITICAL=$CRITICAL)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#Check, if device is a block-device
|
||||
if [ ! -b "$DEVICE" ]
|
||||
then
|
||||
echo "Device $DEVICE does not exist or is not a block-Device"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
RESULT=$($HDDTEMP $DEVICE)
|
||||
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
|
||||
|
||||
#Auswertung der Temperaturen
|
||||
if [ "$OUTTEMPCLEAN" -lt "$WARNING" ]
|
||||
then
|
||||
echo "OK - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT"
|
||||
exit 0
|
||||
elif [ "$OUTTEMPCLEAN" -ge "$WARNING" ] && [ "$OUTTEMPCLEAN" -lt "$CRITICAL" ]
|
||||
then
|
||||
echo "WARNING - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT"
|
||||
exit 3
|
||||
elif [ "$OUTTEMPCLEAN" -ge "$CRITICAL" ]
|
||||
then
|
||||
echo "CRITICAL - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT"
|
||||
exit 2
|
||||
else
|
||||
echo "UNKNOWN - $OUTMODEL on $OUTDEV is $OUTTEMP $PERFRESULT"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user