Nagios Plugins
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

check_raspi_temp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/python3
  2. #
  3. import nagios
  4. import subprocess
  5. GPU_ERROR = 85
  6. GPU_WARNING = 82
  7. #
  8. CPU_ERROR = 85
  9. CPU_WARNING = 82
  10. #
  11. if __name__ == "__main__":
  12. cpu_temp = subprocess.check_output(['cat', '/sys/class/thermal/thermal_zone0/temp']).decode('utf-8')
  13. try:
  14. cpu_temp = int(cpu_temp) / 1000
  15. except ValueError:
  16. cpu_temp = None
  17. gpu_temp = subprocess.check_output(['vcgencmd', 'measure_temp']).decode('utf-8')
  18. gpu_temp = gpu_temp[gpu_temp.find('=')+1:gpu_temp.find("'")]
  19. try:
  20. gpu_temp = float(gpu_temp)
  21. except ValueError:
  22. gpu_temp = None
  23. #
  24. n = nagios.Nagios()
  25. #
  26. if (gpu_temp or 0) > GPU_ERROR:
  27. status = n.ERROR
  28. elif (cpu_temp or 0) > CPU_ERROR:
  29. status = n.ERROR
  30. elif (gpu_temp or 0) > GPU_WARNING:
  31. status = n.WARNING
  32. elif (cpu_temp or 0) > CPU_WARNING:
  33. status = n.WARNING
  34. elif gpu_temp is None or cpu_temp is None:
  35. status = n.UNKNOWN
  36. else:
  37. status = n.OK
  38. #
  39. n.exit(status, f"cpu-temperature={cpu_temp}°C - gpu-temperature: {gpu_temp}°C")