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

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