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.5KB

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