From 9d4f24201007efc48720aad4f83489cf4158ea17 Mon Sep 17 00:00:00 2001 From: Cat5TV Date: Tue, 26 May 2020 13:57:55 -0400 Subject: [PATCH] Add error handling if missing lm-sensors --- data/1.6/nagios/plugins/check_rpi_temperature | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/data/1.6/nagios/plugins/check_rpi_temperature b/data/1.6/nagios/plugins/check_rpi_temperature index 594aa48..87f26b9 100755 --- a/data/1.6/nagios/plugins/check_rpi_temperature +++ b/data/1.6/nagios/plugins/check_rpi_temperature @@ -55,7 +55,18 @@ fi if [[ -e /var/log/nems ]]; then TEMP=`/usr/local/bin/nems-info temperature` else - TEMP=`sensors | grep Core | tr '+°C' ' ' | awk '{print $3}' | head -n 1` + sensors=`which sensors` + if [[ ! $sensors == '' ]]; then + TEMP=`sensors | grep Core | tr '+°C' ' ' | awk '{print $3}' | head -n 1` + fi + if [[ $TEMP == '' ]] && [[ -e /sys/class/thermal/thermal_zone0/temp ]]; then + # this is a dirty way to try to figure it out since it doesn't tell which temp unit we're using... but it may help on some systems... can improve it later + TEMP=`awk '{printf "%3.1f", $1/1000}' /sys/class/thermal/thermal_zone0/temp` + fi + if [[ $TEMP == '' ]]; then + echo "UNKNOWN - Thermal sensor doesn't exist or lm-sensors not installed" + exit 3 + fi fi if (( $(echo "${TEMP} > ${CRIT}" | bc -l) )); then