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.

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