2014-07-25 15:55:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Adapted from check_nagios_latency
|
2019-08-01 15:28:01 +02:00
|
|
|
# https://github.com/larsen0815/check_rasp_temp
|
2014-07-25 15:55:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Prints usage information
|
|
|
|
usage() {
|
|
|
|
|
|
|
|
if [ -n "$1" ] ; then
|
|
|
|
echo "Error: $1" 1>&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
2023-03-13 12:36:17 +01:00
|
|
|
echo "Usage: check_rasp_temp [-hl?] -w warning -c critical"
|
2014-07-25 15:55:58 +02:00
|
|
|
echo ""
|
|
|
|
echo " -w warning threshold"
|
|
|
|
echo " -c critical threshold"
|
2023-03-13 12:36:17 +01:00
|
|
|
echo " -l check for low temperatures"
|
2014-07-25 15:55:58 +02:00
|
|
|
echo " -h, -? this help message"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
exit 3
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Checks if a given program is available and executable
|
|
|
|
check_prog() {
|
|
|
|
|
|
|
|
if [ -z "$PROG" ] ; then
|
2023-03-15 11:11:39 +01:00
|
|
|
PROG=$(which $1)
|
2014-07-25 15:55:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$PROG" ] ; then
|
|
|
|
echo "TEMPERATURE UNKNOWN - cannot find $1"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
PROG=""
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Main
|
2023-03-15 11:07:42 +01:00
|
|
|
check_prog vcgencmd
|
2014-07-25 15:55:58 +02:00
|
|
|
check_prog awk
|
|
|
|
check_prog bc
|
|
|
|
|
|
|
|
|
|
|
|
# process command line options
|
2023-03-13 12:36:17 +01:00
|
|
|
while getopts "hl?c:w:" opt; do
|
2014-07-25 15:55:58 +02:00
|
|
|
case $opt in
|
|
|
|
c ) CRITICAL=$OPTARG; ;;
|
|
|
|
h | \? ) usage ; exit 3; ;;
|
|
|
|
w ) WARNING=$OPTARG; ;;
|
2023-03-13 12:36:17 +01:00
|
|
|
l ) LOW=true; ;;
|
2014-07-25 15:55:58 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
|
|
|
|
# Check options
|
|
|
|
if [ -z "${WARNING}" ] ; then
|
|
|
|
usage "No warning threshold specified"
|
|
|
|
fi
|
|
|
|
if [ -z "${CRITICAL}" ] ; then
|
|
|
|
usage "No critical threshold specified"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check number formats
|
|
|
|
if ! echo $WARNING | grep -qE '^[0-9]+(\.[0-9]+)?$' ; then
|
|
|
|
echo "TEMPERATURE UNKOWN - Wrong number: $WARNING"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
if ! echo $CRITICAL | grep -qE '^[0-9]+(\.[0-9]+)?$' ; then
|
|
|
|
echo "TEMPERATURE UNKOWN - Wrong number: $CRITICAL"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Perform the checks
|
2023-03-15 11:11:39 +01:00
|
|
|
TEMP=$(vcgencmd measure_temp | awk -F"=" '{print $2}' | awk -F"'" '{print $1}')
|
2014-07-25 15:55:58 +02:00
|
|
|
PERF="temp=${TEMP};${WARNING};${CRITICAL};;"
|
|
|
|
|
2023-03-13 12:36:17 +01:00
|
|
|
if [ "$LOW" == true ] ; then
|
2023-03-15 11:11:39 +01:00
|
|
|
COMPARISON=$(echo "if($TEMP<=$CRITICAL) 1 else 0;" | bc)
|
2023-03-13 12:36:17 +01:00
|
|
|
if [ $COMPARISON -eq 1 ] ; then
|
|
|
|
echo "TEMPERATURE CRITICAL: $TEMP | $PERF"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2023-03-15 11:11:39 +01:00
|
|
|
COMPARISON=$(echo "if($TEMP<=$WARNING) 1 else 0;" | bc)
|
2023-03-13 12:36:17 +01:00
|
|
|
if [ $COMPARISON -eq 1 ] ; then
|
|
|
|
echo "TEMPERATURE WARNING: $TEMP | $PERF"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
2023-03-15 11:11:39 +01:00
|
|
|
COMPARISON=$(echo "if($TEMP>=$CRITICAL) 1 else 0;" | bc)
|
2023-03-13 12:36:17 +01:00
|
|
|
if [ $COMPARISON -eq 1 ] ; then
|
|
|
|
echo "TEMPERATURE CRITICAL: $TEMP | $PERF"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2023-03-15 11:11:39 +01:00
|
|
|
COMPARISON=$(echo "if($TEMP>=$WARNING) 1 else 0;" | bc)
|
2023-03-13 12:36:17 +01:00
|
|
|
if [ $COMPARISON -eq 1 ] ; then
|
|
|
|
echo "TEMPERATURE WARNING: $TEMP | $PERF"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-07-25 15:55:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "TEMPERATURE OK: $TEMP | $PERF"
|
|
|
|
exit 0;
|