Browse Source

linkqaulity added for zigbee devices

master
Dirk Alders 11 months ago
parent
commit
a9e9ac1974
4 changed files with 29 additions and 1 deletions
  1. 4
    1
      check_z_heartbeat
  2. 1
    0
      check_z_linkquality
  3. 22
    0
      z_server/devices/__init__.py
  4. 2
    0
      z_server/z_protocol.py

+ 4
- 1
check_z_heartbeat View File

7
 from z_server import config
7
 from z_server import config
8
 from z_server import tcp_socket
8
 from z_server import tcp_socket
9
 from z_server.z_protocol import server as client_prot
9
 from z_server.z_protocol import server as client_prot
10
-from z_server.z_protocol import DID_FOLLOWS_SETPOINT, DID_BATTERY_LEVEL, DID_HEARTBEAT
10
+from z_server.z_protocol import DID_FOLLOWS_SETPOINT, DID_BATTERY_LEVEL, DID_HEARTBEAT, DID_LINKQUALITY
11
 from z_server import socket_protocol
11
 from z_server import socket_protocol
12
 import sys
12
 import sys
13
 
13
 
38
     elif sys.argv[0].endswith('check_z_battery'):
38
     elif sys.argv[0].endswith('check_z_battery'):
39
         sp.send(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, data)
39
         sp.send(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, data)
40
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_BATTERY_LEVEL).get_data()
40
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_BATTERY_LEVEL).get_data()
41
+    elif sys.argv[0].endswith('check_z_linkquality'):
42
+        sp.send(socket_protocol.SID_READ_REQUEST, DID_LINKQUALITY, data)
43
+        sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_LINKQUALITY).get_data()
41
     elif sys.argv[0].endswith('check_z_follow'):
44
     elif sys.argv[0].endswith('check_z_follow'):
42
         sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, data)
45
         sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, data)
43
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_SETPOINT).get_data()
46
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_SETPOINT).get_data()

+ 1
- 0
check_z_linkquality View File

1
+check_z_follow

+ 22
- 0
z_server/devices/__init__.py View File

15
     MONITORING_HEARTBEAT = "heartbeat"
15
     MONITORING_HEARTBEAT = "heartbeat"
16
     MONITORING_BATTERY = "battery"
16
     MONITORING_BATTERY = "battery"
17
     MONITORING_FOLLOW_SETPOINT = "follow_setpoint"
17
     MONITORING_FOLLOW_SETPOINT = "follow_setpoint"
18
+    MONITORING_LINKQUALITY = "linkquality"
18
     #
19
     #
19
     FOLLOW_REQUEST_WARNING = 5      # Seconds, till warning comes up, if device does not follow the command
20
     FOLLOW_REQUEST_WARNING = 5      # Seconds, till warning comes up, if device does not follow the command
20
     FOLLOW_REQUEST_ERROR = 60       # Seconds, till error comes up, if device does not follow the command
21
     FOLLOW_REQUEST_ERROR = 60       # Seconds, till error comes up, if device does not follow the command
23
     BATTERY_LVL_WARNING = 15
24
     BATTERY_LVL_WARNING = 15
24
     BATTERY_LVL_ERROR = 5
25
     BATTERY_LVL_ERROR = 5
25
     #
26
     #
27
+    LINKQUALITY_WARNING = 50
28
+    LINKQUALITY_ERROR = 25
29
+    #
26
     LAST_MSG_WARNING = 6 * 60 * 60
30
     LAST_MSG_WARNING = 6 * 60 * 60
27
     LAST_MSG_ERROR = 24 * 60 * 60
31
     LAST_MSG_ERROR = 24 * 60 * 60
28
 
32
 
40
         self.__state_storage__ = {}
44
         self.__state_storage__ = {}
41
         #
45
         #
42
         self.battery = None
46
         self.battery = None
47
+        self.linkquality = None
43
 
48
 
44
     def __rx__(self, client, userdata, message):
49
     def __rx__(self, client, userdata, message):
45
         try:
50
         try:
66
                 #
71
                 #
67
                 if self.MONITORING_BATTERY in payload and message.topic == self.topic:
72
                 if self.MONITORING_BATTERY in payload and message.topic == self.topic:
68
                     self.battery = payload[self.MONITORING_BATTERY]
73
                     self.battery = payload[self.MONITORING_BATTERY]
74
+                #
75
+                # linkquality
76
+                #
77
+                if self.MONITORING_LINKQUALITY in payload and message.topic == self.topic:
78
+                    self.linkquality = payload[self.MONITORING_LINKQUALITY]
69
 
79
 
70
     def target(self, key, value):
80
     def target(self, key, value):
71
         tm_t, value_t = self.__target_storage__.get(key, (0, None))
81
         tm_t, value_t = self.__target_storage__.get(key, (0, None))
126
                 return self.__nagios_return__(self.MONITORING_BATTERY, nagios.Nagios.WARNING, "Battery level low (%.1f%%)" % self.battery)
136
                 return self.__nagios_return__(self.MONITORING_BATTERY, nagios.Nagios.WARNING, "Battery level low (%.1f%%)" % self.battery)
127
             else:
137
             else:
128
                 return self.__nagios_return__(self.MONITORING_BATTERY, nagios.Nagios.OK, "Battery okay (%.1f%%)" % self.battery)
138
                 return self.__nagios_return__(self.MONITORING_BATTERY, nagios.Nagios.OK, "Battery okay (%.1f%%)" % self.battery)
139
+        #
140
+        # LINKQUALITY
141
+        #
142
+        elif key == self.MONITORING_LINKQUALITY:
143
+            if self.linkquality is None:
144
+                return self.__nagios_return__(self.MONITORING_LINKQUALITY, nagios.Nagios.UNKNOWN, "Device exists, but no data received or unknown monitoring")
145
+            elif self.linkquality <= self.LINKQUALITY_ERROR:
146
+                return self.__nagios_return__(self.MONITORING_LINKQUALITY, nagios.Nagios.ERROR, "Linkquality critical low (%d)" % self.linkquality)
147
+            elif self.linkquality <= self.LINKQUALITY_WARNING:
148
+                return self.__nagios_return__(self.MONITORING_LINKQUALITY, nagios.Nagios.WARNING, "Linkquality level low (%d)" % self.linkquality)
149
+            else:
150
+                return self.__nagios_return__(self.MONITORING_LINKQUALITY, nagios.Nagios.OK, "Linkquality okay (%d)" % self.linkquality)
129
 
151
 
130
     def __nagios_return__(self, monitoring_name, status, msg, force=False):
152
     def __nagios_return__(self, monitoring_name, status, msg, force=False):
131
         tm = time.time()
153
         tm = time.time()

+ 2
- 0
z_server/z_protocol.py View File

5
 DID_FOLLOWS_SETPOINT = 'follow_setpoint'
5
 DID_FOLLOWS_SETPOINT = 'follow_setpoint'
6
 DID_BATTERY_LEVEL = 'battery'
6
 DID_BATTERY_LEVEL = 'battery'
7
 DID_HEARTBEAT = 'heartbeat'
7
 DID_HEARTBEAT = 'heartbeat'
8
+DID_LINKQUALITY = 'linkquality'
8
 
9
 
9
 
10
 
10
 class server(socket_protocol.pure_json_protocol):
11
 class server(socket_protocol.pure_json_protocol):
16
         if not self.__comm_inst__.IS_CLIENT:
17
         if not self.__comm_inst__.IS_CLIENT:
17
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, self.device_status)
18
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, self.device_status)
18
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, self.device_status)
19
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, self.device_status)
20
+            self.register_callback(socket_protocol.SID_READ_REQUEST, DID_LINKQUALITY, self.device_status)
19
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, self.device_status)
21
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, self.device_status)
20
 
22
 
21
     def device_status(self, msg):
23
     def device_status(self, msg):

Loading…
Cancel
Save