Skip to content

Instantly share code, notes, and snippets.

@discarn8
Created March 21, 2022 04:51
Show Gist options
  • Save discarn8/67ad91f2867383bbe75a91c20e8251a5 to your computer and use it in GitHub Desktop.
Save discarn8/67ad91f2867383bbe75a91c20e8251a5 to your computer and use it in GitHub Desktop.
Nagios Check Raspberry Pi Temperature
/usr/lib/nagios/plugins/check_rasp_temp
---------------------------------------------------------
#!/bin/bash
# Adapted from check_nagios_latency
VCGENCMD="/opt/vc/bin/vcgencmd"
# Prints usage information
usage() {
if [ -n "$1" ] ; then
echo "Error: $1" 1>&2
fi
echo ""
echo "Usage: check_rasp_temp [-h?] -w warning -c critical"
echo ""
echo " -w warning threshold"
echo " -c critical threshold"
echo " -h, -? this help message"
echo ""
exit 3
}
# Checks if a given program is available and executable
check_prog() {
if [ -z "$PROG" ] ; then
PROG=`which $1`
fi
if [ -z "$PROG" ] ; then
echo "TEMPERATURE UNKNOWN - cannot find $1"
exit 3
fi
PROG=""
}
# Main - check progs
check_prog awk
check_prog bc
# process command line options
while getopts "h?c:w:" opt; do
case $opt in
c ) CRITICAL=$OPTARG; ;;
h | \? ) usage ; exit 3; ;;
w ) WARNING=$OPTARG; ;;
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
tm=`/opt/vc/bin/vcgencmd measure_temp`
tc=`echo $tm| cut -d '=' -f2 | sed 's/..$//'`
TEMP=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
PERF="temp=${TEMP};${WARNING};${CRITICAL};;"
COMPARISON=`echo "if($TEMP>=$CRITICAL) 1 else 0;" | bc`
if [ $COMPARISON -eq 1 ] ; then
echo "TEMPERATURE CRITICAL: $TEMP | $PERF"
exit 2
fi
COMPARISON=`echo "if($TEMP>=$WARNING) 1 else 0;" | bc`
if [ $COMPARISON -eq 1 ] ; then
echo "TEMPERATURE WARNING: $TEMP | $PERF"
exit 1
fi
echo "TEMPERATURE OK: $TEMP | $PERF"
exit 0;
------------------------------------------------------------
/etc/nagios/nrpe.cfg | egrep -v '#|^$'
------------------------------------------------------------
command[check_users]=/usr/lib/nagios/plugins/check_users -w 3 -c 4
command[check_load]=/usr/lib/nagios/plugins/check_load -r -w 1.95,1.90,1.80 -c 2.10,2.00,1.90
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 250 -c 300
command[check_apt]=/usr/lib/nagios/plugins/check_apt
command[check_ntp]=/usr/lib/nagios/plugins/check_ntp_time -H 1.1.1.1 -w 2 -c 5
command[checknfs]=sudo -u root /usr/lib/nagios/plugins/check_nfs.sh
command[check_hw]=sudo -u root /usr/lib/nagios/plugins/check_hw
command[check_os]=sudo -u root /usr/lib/nagios/plugins/check_os
command[check_rasp_temp]=sudo -u root /usr/lib/nagios/plugins/check_rasp_temp -w 145 -c 165
command[check_throttled]=sudo -u root /usr/lib/nagios/plugins/check_throttled
command[check_v]=sudo -u root /usr/lib/nagios/plugins/check_voltage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment