311 lines
6.9 KiB
Bash
Executable File
311 lines
6.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
|
|
# Beschreibung
|
|
# sudo
|
|
# Um das Script verwenden zu können, wird ein sudo-Eintrag benötigt. Mit folgender zeile kann dieser erstellt werden
|
|
# echo -e "nagios\tALL=(ALL)\tNOPASSWD: /usr/bin/digitemp_DS9097" | sudo tee /etc/sudoers.d/10-check_digitemp_adv
|
|
|
|
|
|
DIGITEMP="$(type -P digitemp_DS9097)"
|
|
|
|
#Welche Werte soll es haben
|
|
#-c Kofigurationsdatei
|
|
#-s sensornummer
|
|
#-S Sensorname
|
|
#-w Warning
|
|
#-c|--crit critical
|
|
#-l|--list list all devices
|
|
#-p|--perfdata
|
|
#-h|--help
|
|
|
|
function hilfetext(){
|
|
cat <<- EOF
|
|
|
|
$(basename "$0") [OPTION...]
|
|
Options:
|
|
--config Path to .digitemprc. Default is the current directory
|
|
-s Display only the following SensorNumber
|
|
-S | --sensor Display only the following SensorID
|
|
-w | --warn Warning Value. Default is 40
|
|
-c | --crit Critical Value. Default is 50
|
|
-l | --list List all sensors
|
|
--celsius Display all temperatures in degree celsius (default)
|
|
--fahrenheit Display all temperatures in degree fahrenheit
|
|
--sensor_hex Output of the Hex-Sensors (default)
|
|
--sensor_nr Output of the Sensor-Numbers
|
|
-p | --perfdata show Performancedata
|
|
-h | --help Print this Help
|
|
|
|
EOF
|
|
}
|
|
|
|
function ParameterEvaluation(){
|
|
|
|
options=$(getopt -o s:S:w:c:lph --long config: --long sensor: --long warn: --long crit: --long list --long celsius --long fahrenheit --long sensor_hex --long sensor_nr --long perfdata --long help -- "$@")
|
|
|
|
#Option nicht verfügbar
|
|
[ "$?" -eq "0" ] || {
|
|
echo "Incorrect option provided"
|
|
exit 1
|
|
}
|
|
|
|
eval set -- "$options"
|
|
while true; do
|
|
case "$1" in
|
|
"--config")
|
|
shift; # The arg is next in position args
|
|
CONFIG_PATH="$1"
|
|
;;
|
|
"-s")
|
|
shift; # The arg is next in position args
|
|
#SENSOR_NUMBER="$1"
|
|
SENSOR_NUMBER+=" $1"
|
|
SENSORS+=" $1"
|
|
;;
|
|
"-S"|"--sensor")
|
|
shift; # The arg is next in position args
|
|
#SENSOR_ID="$1"
|
|
SENSOR_ID+=" $1"
|
|
SENSORS+=" $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"
|
|
;;
|
|
"-l"|"--list")
|
|
LIST="1"
|
|
;;
|
|
"--celsius")
|
|
CELSIUS="1"
|
|
;;
|
|
"--fahrenheit")
|
|
FAHRENHEIT="1"
|
|
;;
|
|
"--sensor_hex")
|
|
DISPLAY_SENSOR_HEX="1"
|
|
;;
|
|
"--sensor_nr")
|
|
DISPLAY_SENSOR_NR="1"
|
|
;;
|
|
"-p"|"--perfdata")
|
|
PERFDATA="1"
|
|
;;
|
|
"-h"|"--help")
|
|
hilfetext
|
|
exit 0
|
|
;;
|
|
|
|
"--")
|
|
shift
|
|
break
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
}
|
|
|
|
#Prüfen, ob digitemp installiert ist
|
|
if [ ! -x "$DIGITEMP" ]
|
|
then
|
|
echo "digitemp_DS9097 nicht gefunden"
|
|
exit 1
|
|
fi
|
|
|
|
DIGITEMP_EXEC="$(type -P sudo) $DIGITEMP"
|
|
|
|
|
|
#Wenn keine Option oder Argument angegeben wurde, wird die Hilfe ausgegeben
|
|
#if [ -z "$PARAMETER" ]
|
|
#then
|
|
# hilfetext
|
|
# exit 0
|
|
#fi
|
|
|
|
|
|
ParameterEvaluation "$0" "$@"
|
|
|
|
#Wenn Parameter CONFIG_PATH nicht gesetzt oder nicht vorhanden, dann wird das lokale gesucht
|
|
if [ ! -r "$CONFIG_PATH" ]
|
|
then
|
|
#DEBUG output
|
|
#echo "CONFIG_PATH \"$CONFIG_PATH\" nicht gefunden"
|
|
if [ ! -r "$(pwd)/.digitemprc" ]
|
|
then
|
|
echo "Config File not found"
|
|
exit 1
|
|
else
|
|
CONFIG_PATH="$(pwd)/.digitemprc"
|
|
fi
|
|
fi
|
|
|
|
|
|
#Wenn der Parameter WARNING nicht gesetzt ist, setze Standardwert
|
|
if [ -z "$WARNING" ]
|
|
then
|
|
WARNING="40"
|
|
fi
|
|
|
|
#Wenn der Parameter CRITICAL nicht gesetzt ist, setze Standardwert
|
|
if [ -z "$CRITICAL" ]
|
|
then
|
|
CRITICAL="50"
|
|
fi
|
|
|
|
#Wenn der Parameter WARNING > CRITICAL beende Programm
|
|
if [ "$WARNING" -gt "$CRITICAL" ]
|
|
then
|
|
echo "Parameter WARNING is greater then CRITICAL"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
#Sollte "--fahrenheit" und "--celsius" gesetzt sein, wird das Script beendet
|
|
if [ "$FAHRENHEIT" = "1" ] && [ "$CELSIUS" = "1" ]
|
|
then
|
|
echo 'Parameter "--celsius" and "--fahrenheit" gesetzt'
|
|
exit 1
|
|
fi
|
|
|
|
#Sollte weder "--fahrenheit" noch "--celsius" gesetzt sein, wird CELSIUS aktiviert
|
|
if [ "$FAHRENHEIT" = "" ] && [ "$CELSIUS" = "" ]
|
|
then
|
|
CELSIUS="1"
|
|
fi
|
|
|
|
|
|
#Sollte "--sensor_nr" und "--sensor_hex" gesetzt sein, wird das Script beendet
|
|
if [ "$DISPLAY_SENSOR_HEX" = "1" ] && [ "$DISPLAY_SENSOR_NR" = "1" ]
|
|
then
|
|
echo 'Parameter "--sensor_nr" and "--sensor_hex" gesetzt'
|
|
exit 1
|
|
fi
|
|
|
|
#Sollte weder "--sensor_nr" noch "--sensor_hex" gesetzt sein, wird DISPLAY_SENSOR_HEX aktiviert
|
|
if [ "$DISPLAY_SENSOR_HEX" = "" ] && [ "$DISPLAY_SENSOR_NR" = "" ]
|
|
then
|
|
DISPLAY_SENSOR_HEX="1"
|
|
fi
|
|
|
|
|
|
if [ "$LIST" = "1" ]
|
|
then
|
|
$DIGITEMP -c "$CONFIG_PATH" -a -o"Sensor %s: Serial %R" -q
|
|
exit 0
|
|
fi
|
|
|
|
|
|
#SENSORS="$SENSOR_NUMBER $SENSOR_ID"
|
|
#DEBUG
|
|
#echo "SENSORS: \"$SENSORS\""
|
|
|
|
#Initialisieren der Variablen
|
|
STATUS_CRITICAL=0
|
|
STATUS_WARNING=0
|
|
STATUS_OK=0
|
|
|
|
|
|
for wert in $($DIGITEMP_EXEC -c "$CONFIG_PATH" -a -o"%s;%R;%.0C;%.0F" -q)
|
|
do
|
|
sensor_id=$(echo "$wert" | cut -d ";" -f 1)
|
|
sensor_hex=$(echo "$wert" | cut -d ";" -f 2)
|
|
celsius=$(echo "$wert" | cut -d ";" -f 3)
|
|
fahrenheit=$(echo "$wert" | cut -d ";" -f 4)
|
|
|
|
#Debug flag
|
|
#echo -e "sensor_id: $sensor_id; sensor_hex: $sensor_hex; celsius: $celsius; fahrenheit: $fahrenheit"
|
|
|
|
#if [[ "$SENSORS" ~= "$sensor_id" ]]
|
|
#then
|
|
|
|
if [ "$CELSIUS" = "1" ]
|
|
then
|
|
if [ "$celsius" -ge "$CRITICAL" ]
|
|
then
|
|
STATUS_CRITICAL=$(( STATUS_CRITICAL + 1 ))
|
|
#echo "ToDo: Ausgabe CRITICAL"
|
|
elif [ "$celsius" -ge "$WARNING" ]
|
|
then
|
|
STATUS_WARNING=$(( STATUS_WARNING + 1 ))
|
|
#echo "ToDo: Ausgabe Warning"
|
|
else
|
|
STATUS_OK=$(( STATUS_OK + 1 ))
|
|
#echo "ToDo: Ausgabe OK"
|
|
fi
|
|
|
|
if [ "$DISPLAY_SENSOR_HEX" = "1" ]
|
|
then
|
|
OUTPUT+=" Sensor $sensor_hex is ${celsius}°C;"
|
|
OUTPUT_PERFDATA+="Sensor $sensor_hex=$celsius;$WARNING;$CRITICAL "
|
|
elif [ "$DISPLAY_SENSOR_NR" = "1" ]
|
|
then
|
|
OUTPUT+=" Sensor $sensor_id is ${celsius}°C;"
|
|
OUTPUT_PERFDATA+="Sensor $sensor_id=$celsius;$WARNING;$CRITICAL "
|
|
fi
|
|
|
|
|
|
fi
|
|
|
|
if [ "$FAHRENHEIT" = "1" ]
|
|
then
|
|
if [ "$fahrenheit" -ge "$CRITICAL" ]
|
|
then
|
|
STATUS_CRITICAL=$(( STATUS_CRITICAL + 1 ))
|
|
#echo "ToDo: Ausgabe CRITICAL"
|
|
elif [ "$fahrenheit" -ge "$WARNING" ]
|
|
then
|
|
STATUS_WARNING=$(( STATUS_WARNING + 1 ))
|
|
#echo "ToDo: Ausgabe Warning"
|
|
else
|
|
STATUS_OK=$(( STATUS_OK + 1 ))
|
|
#echo "ToDo: Ausgabe OK"
|
|
fi
|
|
|
|
if [ "$DISPLAY_SENSOR_HEX" = "1" ]
|
|
then
|
|
OUTPUT+=" Sensor $sensor_hex is ${fahrenheit}°F;"
|
|
OUTPUT_PERFDATA+="Sensor $sensor_hex=$fahrenheit;$WARNING;$CRITICAL "
|
|
elif [ "$DISPLAY_SENSOR_NR" = "1" ]
|
|
then
|
|
OUTPUT+=" Sensor $sensor_id is ${fahrenheit}°F;"
|
|
OUTPUT_PERFDATA+="Sensor $sensor_id=$fahrenheit;$WARNING;$CRITICAL "
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
done
|
|
|
|
#Debug output
|
|
#echo -e "STATUS_CRITICAL:\t$STATUS_CRITICAL\nSTATUS_WARNING:\t$STATUS_WARNING\nSTATUS_OK:\t$STATUS_OK"
|
|
#echo -e "OUTPUT: $OUTPUT"
|
|
|
|
#Wenn der schalter --perfdata gesetzt ist, wird die Ausgabe um $STATUS_OK, $STATUS_WARNING und $STATUS_CRITICAL erweitert
|
|
if [ "$PERFDATA" = "1" ]
|
|
then
|
|
OUTPUT="$OUTPUT | $OUTPUT_PERFDATA"
|
|
fi
|
|
|
|
##############################################
|
|
# Auswertung des Status und aufbereitung für nrpe
|
|
if [ ! "$STATUS_CRITICAL" = "0" ]
|
|
then
|
|
echo "CRITICAL -$OUTPUT"
|
|
exit 2
|
|
elif [ ! "$STATUS_WARNING" = "0" ]
|
|
then
|
|
echo "WARNING -$OUTPUT"
|
|
exit 1
|
|
elif [ ! "$STATUS_OK" = "0" ]
|
|
then
|
|
echo "OK -$OUTPUT"
|
|
exit 0
|
|
else
|
|
echo "UNKNOWN -$OUTPUT"
|
|
exit 3
|
|
fi
|