34 lines
1.6 KiB
Python
34 lines
1.6 KiB
Python
import nagios
|
|
import socket_protocol
|
|
# from devdi.topic import topic_by_props
|
|
|
|
DID_FOLLOWS_HEATING_SETPOINT = 'current_heating_setpoint'
|
|
DID_BATTERY_LEVEL = 'battery'
|
|
|
|
|
|
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)
|
|
#
|
|
# self.add_data((socket_protocol.SID_READ_REQUEST, socket_protocol.SID_READ_RESPONSE),
|
|
# DID_FOLLOWS_HEATING_SETPOINT, 'current_heating_setpoint')
|
|
#
|
|
if not self.__comm_inst__.IS_CLIENT:
|
|
self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, self.device_status)
|
|
self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, 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": "Exception while getting device."}
|
|
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."}
|