#!/bin/bash ################################################################################ # # 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 # # The warning and critical values are from a 2007 Google study (Failure Trends in a Large Disk Drive Population) # ################################################################################ HDDTEMP="$(type -P hddtemp)" PARAMETER="$*" WARNING="40" CRITICAL="45" UNIT="c" function hilfetext(){ cat <<- EOF $(basename "$0") [OPTION...] Options: -d | --device --fahrenheit --celsius (default) -w | --warning (default: 40) -c | --critical (default: 50) -p | --perfdata -h | --help EOF } function ParameterEvaluation(){ 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" ;; "--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 ;; "--") 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\"" #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 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=;; 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 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