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.

__init__.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import json
  2. import logging
  3. import mqtt
  4. import nagios
  5. import time
  6. try:
  7. from config import APP_NAME as ROOT_LOGGER_NAME
  8. except ImportError:
  9. ROOT_LOGGER_NAME = 'root'
  10. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  11. class base(object):
  12. FOLLOW_REQUEST_WARNING = 5 # Seconds, till warning comes up, if device does not follow the command
  13. FOLLOW_REQUEST_ERROR = 60 # Seconds, till error comes up, if device does not follow the command
  14. def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
  15. self.topic = topic
  16. #
  17. mqtt_client.add_callback(topic, self.__rx__)
  18. mqtt_client.add_callback(topic + '/#', self.__rx__)
  19. #
  20. self.__target_storage__ = {}
  21. self.__state_storage__ = {}
  22. def __rx__(self, client, userdata, message):
  23. pass
  24. def target(self, key, value):
  25. tm_t, value_t = self.__target_storage__.get(key, (0, None))
  26. if value != value_t:
  27. self.__target_storage__[key] = time.time(), value
  28. logger.debug("Target value for device identified: %s: %s", key, repr(value))
  29. def state(self, key, value):
  30. self.__state_storage__[key] = value
  31. logger.debug("Device state identified: %s: %s", key, repr(value))
  32. def status(self, key):
  33. try:
  34. tm_t, value_t = self.__target_storage__[key]
  35. value_s = self.__state_storage__.get(key)
  36. except KeyError:
  37. return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exists, but no setpoint change or unknown monitoring"}
  38. else:
  39. tm = time.time()
  40. dt = tm - tm_t
  41. if value_t != value_s and dt > self.FOLLOW_REQUEST_ERROR:
  42. return {"status": nagios.Nagios.ERROR, "msg": "Requested setpoint unequal valve setpoint since %.1fs" % dt}
  43. elif value_t != value_s and dt > self.FOLLOW_REQUEST_WARNING:
  44. return {"status": nagios.Nagios.WARNING, "msg": "Requested setpoint unequal valve setpoint since %.1fs" % dt}
  45. return {"status": nagios.Nagios.OK, "msg": "Requested setpoint equal valve setpoint"}
  46. class group(object):
  47. def __init__(self, *args, **kwargs):
  48. pass
  49. class shelly_sw1(base):
  50. pass
  51. class tradfri_sw(base):
  52. pass
  53. class tradfri_sw_br(base):
  54. pass
  55. class tradfri_sw_br_ct(base):
  56. pass
  57. class tradfri_button(base):
  58. pass
  59. class livarno_sw_br_ct(base):
  60. pass
  61. class brennenstuhl_heatingvalve(base):
  62. def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
  63. base.__init__(self, mqtt_client, topic)
  64. def __rx__(self, client, userdata, message):
  65. payload = json.loads(message.payload)
  66. if message.topic == self.topic + '/set':
  67. self.target("current_heating_setpoint", payload["current_heating_setpoint"])
  68. if message.topic == self.topic:
  69. self.state("current_heating_setpoint", payload["current_heating_setpoint"])
  70. class silvercrest_powerplug(base):
  71. pass
  72. class silvercrest_motion_sensor(base):
  73. pass
  74. class my_powerplug(base):
  75. pass
  76. class audio_status(base):
  77. pass
  78. class remote(base):
  79. pass