2020-10-03 16:20:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Created by Jonny007-MKD 2020-10-03
|
|
|
|
|
|
|
|
echoerr() { echo "$@" 1>&2; }
|
|
|
|
|
2020-10-17 07:20:26 +02:00
|
|
|
pathToBc=$(command -v bc)
|
|
|
|
if [ $? -ne 0 ]; then
|
2020-10-03 16:46:52 +02:00
|
|
|
echoerr Please install bc
|
|
|
|
exit -2
|
|
|
|
fi
|
|
|
|
|
2022-07-15 20:01:29 +02:00
|
|
|
pathToVcGenCmd=/usr/bin/vcgencmd
|
|
|
|
if [ ! -x "$pathToVcGenCmd" ]; then
|
|
|
|
pathToVcGenCmd=/opt/vc/bin/vcgencmd
|
|
|
|
fi
|
|
|
|
if [ ! -x "$pathToVcGenCmd" ]; then
|
|
|
|
pathToVcGenCmd=$(which vcgencmd 2> /dev/null)
|
|
|
|
fi
|
|
|
|
if [ ! -x "$pathToVcGenCmd" ]; then
|
|
|
|
echoerr Cannot find vcgencmd
|
|
|
|
exit -3
|
|
|
|
fi
|
2020-10-03 16:46:52 +02:00
|
|
|
|
2020-10-03 16:20:58 +02:00
|
|
|
WARN=50
|
|
|
|
CRIT=70
|
|
|
|
FAHRENHEIT=false
|
|
|
|
DEBUG=false
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
-w|--warn|--warning)
|
|
|
|
case "$2" in
|
2020-10-03 16:46:52 +02:00
|
|
|
''|*[!0-9]*) echoerr "Value for \"$1\" has to be a number"; exit -3;;
|
2020-10-03 16:20:58 +02:00
|
|
|
esac
|
|
|
|
WARN=$2
|
2021-01-17 12:59:36 +01:00
|
|
|
shift
|
2020-10-03 16:20:58 +02:00
|
|
|
;;
|
|
|
|
-c|--crit|--critical)
|
|
|
|
case "$2" in
|
2020-10-03 16:46:52 +02:00
|
|
|
''|*[!0-9]*) echoerr "Value for \"$1\" has to be a number"; exit -3;;
|
2020-10-03 16:20:58 +02:00
|
|
|
esac
|
|
|
|
CRIT=$2
|
2021-01-17 12:59:36 +01:00
|
|
|
shift
|
2020-10-03 16:20:58 +02:00
|
|
|
;;
|
|
|
|
-f|--fahrenheit)
|
|
|
|
FAHRENHEIT=true
|
|
|
|
;;
|
|
|
|
-d|--debug)
|
|
|
|
DEBUG=true
|
|
|
|
;;
|
|
|
|
-?|--help)
|
|
|
|
echo "Check /proc/mdstat. Arguments:"
|
|
|
|
echo "--warning $WARN: Temperature above which the result is warning"
|
|
|
|
echo "--critical $CRIT: Temperature above which the result is critical"
|
|
|
|
echo "--fahrenheit: All temperatures in Fahrenheit (°F)"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $CRIT -le $WARN ]; then
|
|
|
|
echoerr "Critical threshold ($CRIT) has to be greater than Warning threshold ($WARN)"
|
2020-10-03 16:46:52 +02:00
|
|
|
exit -3
|
2020-10-03 16:20:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
function log {
|
|
|
|
if $DEBUG; then
|
|
|
|
echo " > $@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
NL=$'\n'
|
|
|
|
|
|
|
|
|
2022-07-15 20:01:29 +02:00
|
|
|
output=$($pathToVcGenCmd measure_temp)
|
2020-10-03 16:20:58 +02:00
|
|
|
result=$?
|
|
|
|
log vcgencmd: $result. $output
|
|
|
|
if [ $result -ne 0 ]; then
|
|
|
|
echoerr "vcgencmd returned $result"
|
|
|
|
exit $result
|
|
|
|
fi
|
|
|
|
|
|
|
|
temp=${output/temp=/}
|
|
|
|
temp=${temp/\'C/}
|
|
|
|
|
2020-10-03 16:49:06 +02:00
|
|
|
unit="'C"
|
2020-10-03 16:20:58 +02:00
|
|
|
if $FAHRENHEIT; then
|
|
|
|
temp=$(bc <<< "scale=1; ($temp * 1.8) + 32")
|
2020-10-03 16:49:06 +02:00
|
|
|
unit="'F"
|
2020-10-03 16:20:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2021-01-17 12:59:36 +01:00
|
|
|
log "$temp$unit. Warn: $WARN, Crit: $CRIT"
|
2020-10-03 16:20:58 +02:00
|
|
|
|
|
|
|
c=$(bc <<< "$temp > $CRIT")
|
|
|
|
w=$(bc <<< "$temp > $WARN")
|
|
|
|
if [ $c -eq 1 ]; then
|
|
|
|
result="CRITICAL"
|
|
|
|
elif [ $w -eq 1 ]; then
|
|
|
|
result="WARNING"
|
|
|
|
else
|
|
|
|
result="OK"
|
|
|
|
fi
|
2020-10-03 16:49:06 +02:00
|
|
|
echo "$result. $temp$unit | 'temperature'=$temp;$unit;$WARN;$CRIT;-40;85"
|
2020-10-03 16:20:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
case $result in
|
|
|
|
OK) exit 0;;
|
|
|
|
WARNING) exit 1;;
|
|
|
|
CRITICAL) exit 2;;
|
|
|
|
esac
|
|
|
|
|