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.

z_protocol.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435
  1. import nagios
  2. import socket_protocol
  3. # from devdi.topic import topic_by_props
  4. DID_FOLLOWS_HEATING_SETPOINT = 'current_heating_setpoint'
  5. DID_BATTERY_LEVEL = 'battery'
  6. DID_HEARTBEAT = 'heartbeat'
  7. class server(socket_protocol.pure_json_protocol):
  8. def __init__(self, *args, **kwargs):
  9. if 'devices' in kwargs:
  10. self.__devices__ = kwargs.pop('devices')
  11. socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
  12. #
  13. # self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE),
  14. # DID_FOLLOWS_HEATING_SETPOINT, 'current_heating_setpoint')
  15. #
  16. if not self.__comm_inst__.IS_CLIENT:
  17. self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, self.device_status)
  18. self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, self.device_status)
  19. self.register_callback(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, self.device_status)
  20. def device_status(self, msg):
  21. if msg.get_status() == socket_protocol.STATUS_OKAY:
  22. try:
  23. dev = self.__devices__.get_str(**msg.get_data())
  24. except:
  25. return socket_protocol.STATUS_CALLBACK_ERROR, {"status": nagios.Nagios.UNKNOWN, "msg": "Exception while getting device."}
  26. if dev is None:
  27. return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, {"status": nagios.Nagios.UNKNOWN, "msg": "Device does not exist."}
  28. else:
  29. return socket_protocol.STATUS_OKAY, dev.status(msg.get_data_id())
  30. else:
  31. return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, {"status": nagios.Nagios.UNKNOWN, "msg": "Socket protocol error."}