icinga-plugins/checks/check_hddtemp.sh

189 lines
3.9 KiB
Bash
Raw Normal View History

#!/bin/bash
2019-10-13 20:15:02 +02:00
################################################################################
#
# This plugin checks the temperature via hddtemp
#
# I wrote this check-Script, because all other tools didn't do what I wanted.
# The goal was:
# - hddtemp is to be used (small, fast)
# - a better output (with manufacturer and model)
# - deliver performance data
# - options in linux style
# - it should do its job perfectly
#
2019-10-13 20:30:58 +02:00
# The warning and critical values are from a 2007 Google study (Failure Trends in a Large Disk Drive Population)
2019-10-13 20:15:02 +02:00
#
################################################################################
2019-10-22 08:12:38 +02:00
HDDTEMP="$(type -P hddtemp)"
PARAMETER="$*"
WARNING="40"
2019-10-13 20:30:58 +02:00
CRITICAL="45"
2019-10-22 08:13:08 +02:00
UNIT="c"
function hilfetext(){
cat <<- EOF
$(basename "$0") [OPTION...]
Options:
-d | --device
2019-10-22 08:13:08 +02:00
--fahrenheit
--celsius (default)
-w | --warning (default: 40)
-c | --critical (default: 50)
-p | --perfdata
-h | --help
2019-10-22 08:13:08 +02:00
EOF
}
function ParameterEvaluation(){
2019-10-22 08:13:08 +02:00
options=$(getopt -o c:d:hpw: --long fahrenheit --long celsius --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"
;;
2019-10-22 08:13:08 +02:00
"--celsius")
UNIT="c"
;;
"--fahrenheit")
UNIT="f"
;;
"-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
;;
2019-10-22 08:13:08 +02:00
"--")
shift
break
;;
esac
shift
done
}
#Prüfen, ob hddtemp installiert ist
if [ ! -x "$HDDTEMP" ]
then
echo "hddtemp nicht gefunden"
exit 1
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\""
2019-10-22 08:17:19 +02:00
#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
2019-10-22 08:13:08 +02:00
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}')
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"
2019-10-13 20:14:42 +02:00
exit 1
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