Compare commits

...

2 commits

Author SHA1 Message Date
Jonny007-MKD 4bc4fd5c07 Add temperature as status output, too 2020-10-03 16:49:06 +02:00
Jonny007-MKD 662d6622cc Added check for bc 2020-10-03 16:46:52 +02:00
2 changed files with 18 additions and 6 deletions

View file

@ -2,9 +2,15 @@
Icinga2/Nagios check program for Raspberry Pi temperature
## Requirements
- `bc` for floating point calculation
- Adding executing user to video group: `sudo adduser nagios video`. Otherwise "VCHI initialization failed"
## Arguments
- `--warning 50`: Temperature above which the result is warning
- `--critical 70`: Temperature above which the result is critical
- `--fahrenheit`: All temperatures in Fahrenheit (°F)

View file

@ -4,6 +4,12 @@
echoerr() { echo "$@" 1>&2; }
if ! $(command -v bc); then
echoerr Please install bc
exit -2
fi
WARN=50
CRIT=70
FAHRENHEIT=false
@ -12,14 +18,14 @@ while [[ $# -gt 0 ]]; do
case $1 in
-w|--warn|--warning)
case "$2" in
''|*[!0-9]*) echoerr "Argument for \"$1\" has to be a number";;
''|*[!0-9]*) echoerr "Value for \"$1\" has to be a number"; exit -3;;
esac
WARN=$2
shift; shift
;;
-c|--crit|--critical)
case "$2" in
''|*[!0-9]*) echoerr "Argument for \"$1\" has to be a number";;
''|*[!0-9]*) echoerr "Value for \"$1\" has to be a number"; exit -3;;
esac
CRIT=$2
shift; shift
@ -45,7 +51,7 @@ done
if [ $CRIT -le $WARN ]; then
echoerr "Critical threshold ($CRIT) has to be greater than Warning threshold ($WARN)"
exit 1
exit -3
fi
@ -68,10 +74,10 @@ fi
temp=${output/temp=/}
temp=${temp/\'C/}
unit="°C"
unit="'C"
if $FAHRENHEIT; then
temp=$(bc <<< "scale=1; ($temp * 1.8) + 32")
unit="°F"
unit="'F"
fi
@ -85,7 +91,7 @@ elif [ $w -eq 1 ]; then
else
result="OK"
fi
echo "$result | 'temperature'=$temp;$unit;$WARN;$CRIT;-40;85"
echo "$result. $temp$unit | 'temperature'=$temp;$unit;$WARN;$CRIT;-40;85"
case $result in