From 1fff8f14c4527c94c1e17487dda04f5579613935 Mon Sep 17 00:00:00 2001 From: larsen0815 Date: Mon, 13 Mar 2023 12:36:17 +0100 Subject: [PATCH] Possibility to check for low temperatures --- check_rasp_temp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/check_rasp_temp b/check_rasp_temp index a2521de..1356584 100644 --- a/check_rasp_temp +++ b/check_rasp_temp @@ -12,10 +12,11 @@ usage() { fi echo "" - echo "Usage: check_rasp_temp [-h?] -w warning -c critical" + echo "Usage: check_rasp_temp [-hl?] -w warning -c critical" echo "" echo " -w warning threshold" echo " -c critical threshold" + echo " -l check for low temperatures" echo " -h, -? this help message" echo "" @@ -46,11 +47,12 @@ check_prog bc # process command line options -while getopts "h?c:w:" opt; do +while getopts "hl?c:w:" opt; do case $opt in c ) CRITICAL=$OPTARG; ;; h | \? ) usage ; exit 3; ;; w ) WARNING=$OPTARG; ;; + l ) LOW=true; ;; esac done shift $(($OPTIND - 1)) @@ -79,16 +81,30 @@ fi TEMP=`$VCGENCMD measure_temp | awk -F"=" '{print $2}' | awk -F"'" '{print $1}'` 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 +if [ "$LOW" == true ] ; then + 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 +else + 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 fi echo "TEMPERATURE OK: $TEMP | $PERF"