Compare commits
	
		
			2 commits
		
	
	
		
			ae8122a38c
			...
			bf1b51c664
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						bf1b51c664 | ||
| 
							 | 
						a02420a9e5 | 
					 2 changed files with 104 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,10 @@
 | 
			
		|||
# check_rpi_temperature
 | 
			
		||||
 | 
			
		||||
Icinga2/Nagios check program for Raspberry Pi temperature
 | 
			
		||||
Icinga2/Nagios check program for Raspberry Pi temperature
 | 
			
		||||
 | 
			
		||||
## Arguments
 | 
			
		||||
 | 
			
		||||
- `--warning 50`: Temperature above which the result is warning
 | 
			
		||||
- `--critical 70`: Temperature above which the result is critical
 | 
			
		||||
- `--fahrenheit`: All temperatures in Fahrenheit (°F)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										96
									
								
								check_rpi_temp.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										96
									
								
								check_rpi_temp.sh
									
									
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,96 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
#
 | 
			
		||||
# Created by Jonny007-MKD 2020-10-03
 | 
			
		||||
 | 
			
		||||
echoerr() { echo "$@" 1>&2; }
 | 
			
		||||
 | 
			
		||||
WARN=50
 | 
			
		||||
CRIT=70
 | 
			
		||||
FAHRENHEIT=false
 | 
			
		||||
DEBUG=false
 | 
			
		||||
while [[ $# -gt 0 ]]; do
 | 
			
		||||
	case $1 in
 | 
			
		||||
		-w|--warn|--warning)
 | 
			
		||||
			case "$2" in
 | 
			
		||||
				''|*[!0-9]*) echoerr "Argument for \"$1\" has to be a number";;
 | 
			
		||||
			esac
 | 
			
		||||
			WARN=$2
 | 
			
		||||
			shift; shift
 | 
			
		||||
			;;
 | 
			
		||||
		-c|--crit|--critical)
 | 
			
		||||
			case "$2" in
 | 
			
		||||
				''|*[!0-9]*) echoerr "Argument for \"$1\" has to be a number";;
 | 
			
		||||
			esac
 | 
			
		||||
			CRIT=$2
 | 
			
		||||
			shift; shift
 | 
			
		||||
			;;
 | 
			
		||||
		-f|--fahrenheit)
 | 
			
		||||
			FAHRENHEIT=true
 | 
			
		||||
			shift
 | 
			
		||||
			;;
 | 
			
		||||
		-d|--debug)
 | 
			
		||||
			DEBUG=true
 | 
			
		||||
			shift
 | 
			
		||||
			;;
 | 
			
		||||
		-?|--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)"
 | 
			
		||||
	exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function log {
 | 
			
		||||
	if $DEBUG; then
 | 
			
		||||
		echo "  > $@"
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
NL=$'\n'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
output=$(/opt/vc/bin/vcgencmd measure_temp)
 | 
			
		||||
result=$?
 | 
			
		||||
log vcgencmd: $result. $output
 | 
			
		||||
if [ $result -ne 0 ]; then
 | 
			
		||||
	echoerr "vcgencmd returned $result"
 | 
			
		||||
	exit $result
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
temp=${output/temp=/}
 | 
			
		||||
temp=${temp/\'C/}
 | 
			
		||||
 | 
			
		||||
unit="°C"
 | 
			
		||||
if $FAHRENHEIT; then
 | 
			
		||||
	temp=$(bc <<< "scale=1; ($temp * 1.8) + 32")
 | 
			
		||||
	unit="°F"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
echo "$result | 'temperature'=$temp;$unit;$WARN;$CRIT;-40;85"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
case $result in
 | 
			
		||||
	OK)       exit 0;;
 | 
			
		||||
	WARNING)  exit 1;;
 | 
			
		||||
	CRITICAL) exit 2;;
 | 
			
		||||
esac
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in a new issue