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

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