1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import nagios
- import socket_protocol
- # from devdi.topic import topic_by_props
-
- DID_ACTOR = 'actor'
- DID_BATTERY_LEVEL = 'battery'
- DID_FOLLOWS_SETPOINT = 'follow'
- DID_HEARTBEAT = 'heartbeat'
- DID_LINKQUALITY = 'linkquality'
- #
- DIDS = (
- DID_ACTOR,
- DID_BATTERY_LEVEL,
- DID_FOLLOWS_SETPOINT,
- DID_HEARTBEAT,
- DID_LINKQUALITY
- )
-
-
- class server(socket_protocol.pure_json_protocol):
- def __init__(self, *args, **kwargs):
- if 'devices' in kwargs:
- self.__devices__ = kwargs.pop('devices')
- socket_protocol.pure_json_protocol.__init__(self, *args, **kwargs)
- #
- if not self.__comm_inst__.IS_CLIENT:
- for did in DIDS:
- self.register_callback(socket_protocol.SID_READ_REQUEST, did, self.device_status)
-
- def device_status(self, msg):
- if msg.get_status() == socket_protocol.STATUS_OKAY:
- try:
- dev = self.__devices__.get_str(**msg.get_data())
- except:
- return socket_protocol.STATUS_CALLBACK_ERROR, {"status": nagios.Nagios.UNKNOWN, "msg": "Device does not exist."}
- if dev is None:
- return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, {"status": nagios.Nagios.UNKNOWN, "msg": "Device does not exist."}
- else:
- return socket_protocol.STATUS_OKAY, dev.status(msg.get_data_id())
- else:
- return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, {"status": nagios.Nagios.UNKNOWN, "msg": "Socket protocol error."}
|