Nagios Plugins
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

z_protocol.py 1.5KB

1234567891011121314151617181920212223242526272829303132
  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. 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. if not self.__comm_inst__.IS_CLIENT:
  14. self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, self.device_status)
  15. self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, self.device_status)
  16. self.register_callback(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, self.device_status)
  17. def device_status(self, msg):
  18. if msg.get_status() == socket_protocol.STATUS_OKAY:
  19. try:
  20. dev = self.__devices__.get_str(**msg.get_data())
  21. except:
  22. return socket_protocol.STATUS_CALLBACK_ERROR, {"status": nagios.Nagios.UNKNOWN, "msg": "Device does not exist."}
  23. if dev is None:
  24. return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, {"status": nagios.Nagios.UNKNOWN, "msg": "Device does not exist."}
  25. else:
  26. return socket_protocol.STATUS_OKAY, dev.status(msg.get_data_id())
  27. else:
  28. return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, {"status": nagios.Nagios.UNKNOWN, "msg": "Socket protocol error."}