first Release
This commit is contained in:
commit
7438ccd459
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.digitemprc
|
260
check_digitemp_adv.sh
Executable file
260
check_digitemp_adv.sh
Executable file
@ -0,0 +1,260 @@
|
||||
#!/bin/bash
|
||||
|
||||
DIGITEMP="$(type -P digitemp_DS9097)"
|
||||
PARAMETER="$*"
|
||||
|
||||
#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
|
||||
-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 perfdata --long help --long celsius --long fahrenheit -- "$@")
|
||||
|
||||
#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"
|
||||
;;
|
||||
"-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
|
||||
|
||||
#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 weder --fahrenheit noch --celsius gesetzt sein, wird CELSIUS aktiviert
|
||||
if [ "$FAHRENHEIT" = "" -a "$CELSIUS" = "" ]
|
||||
then
|
||||
CELSIUS="1"
|
||||
fi
|
||||
|
||||
#Sollte --fahrenheit und --celsius gesetzt sein, wird das Script beednet
|
||||
if [ "$FAHRENHEIT" = "1" -a "$CELSIUS" = "1" ]
|
||||
then
|
||||
echo 'Parameter "--celsius" and "--fahrenheit" gesetzt'
|
||||
exit 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\""
|
||||
|
||||
|
||||
STATUS_CRITICAL=0
|
||||
STATUS_WARNING=0
|
||||
STATUS_OK=0
|
||||
|
||||
|
||||
for wert in $($DIGITEMP -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
|
||||
|
||||
OUTPUT+=" Sensor $sensor_hex is ${celsius}°C;"
|
||||
|
||||
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
|
||||
|
||||
OUTPUT+=" Sensor $sensor_hex is ${fahrenheit}°F;"
|
||||
|
||||
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 | $STATUS_OK;$STATUS_WARNING;$STATUS_CRITICAL"
|
||||
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
|
Loading…
Reference in New Issue
Block a user