diff --git a/check_raspi_temp b/check_raspi_temp new file mode 100755 index 0000000..c74816e --- /dev/null +++ b/check_raspi_temp @@ -0,0 +1,43 @@ +#!/bin/python3 +# +import argparse +import nagios +import subprocess + +GPU_ERROR = 80 +GPU_WARNING = 75 +# +CPU_ERROR = 80 +CPU_WARNING = 75 +# + +if __name__ == "__main__": + cpu_temp = subprocess.check_output(['cat', '/sys/class/thermal/thermal_zone0/temp']).decode('utf-8') + try: + cpu_temp = int(cpu_temp) / 1000 + except ValueError: + cpu_temp = None + + gpu_temp = subprocess.check_output(['vcgencmd', 'measure_temp']).decode('utf-8') + gpu_temp = gpu_temp[gpu_temp.find('=')+1:gpu_temp.find("'")] + try: + gpu_temp = float(gpu_temp) + except ValueError: + gpu_temp = None + # + n = nagios.Nagios() + # + if (gpu_temp or 0) > GPU_ERROR: + status = n.ERROR + elif (cpu_temp or 0) > CPU_ERROR: + status = n.ERROR + elif (gpu_temp or 0) > GPU_WARNING: + status = n.WARNING + elif (cpu_temp or 0) > CPU_WARNING: + status = n.WARNING + elif gpu_temp is None or cpu_temp is None: + status = n.UNKNOWN + else: + status = n.OK + # + n.exit(status, f"cpu-temperature={cpu_temp}°C - gpu-temperature: {gpu_temp}°C")