Просмотр исходного кода

linkqaulity added for zigbee devices

master
Dirk Alders 11 месяцев назад
Родитель
Сommit
a9e9ac1974
4 измененных файлов: 29 добавлений и 1 удалений
  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 Просмотреть файл

@@ -7,7 +7,7 @@ import time
7 7
 from z_server import config
8 8
 from z_server import tcp_socket
9 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 11
 from z_server import socket_protocol
12 12
 import sys
13 13
 
@@ -38,6 +38,9 @@ if __name__ == '__main__':
38 38
     elif sys.argv[0].endswith('check_z_battery'):
39 39
         sp.send(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, data)
40 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 44
     elif sys.argv[0].endswith('check_z_follow'):
42 45
         sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, data)
43 46
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_SETPOINT).get_data()

+ 1
- 0
check_z_linkquality Просмотреть файл

@@ -0,0 +1 @@
1
+check_z_follow

+ 22
- 0
z_server/devices/__init__.py Просмотреть файл

@@ -15,6 +15,7 @@ class base(object):
15 15
     MONITORING_HEARTBEAT = "heartbeat"
16 16
     MONITORING_BATTERY = "battery"
17 17
     MONITORING_FOLLOW_SETPOINT = "follow_setpoint"
18
+    MONITORING_LINKQUALITY = "linkquality"
18 19
     #
19 20
     FOLLOW_REQUEST_WARNING = 5      # Seconds, till warning comes up, if device does not follow the command
20 21
     FOLLOW_REQUEST_ERROR = 60       # Seconds, till error comes up, if device does not follow the command
@@ -23,6 +24,9 @@ class base(object):
23 24
     BATTERY_LVL_WARNING = 15
24 25
     BATTERY_LVL_ERROR = 5
25 26
     #
27
+    LINKQUALITY_WARNING = 50
28
+    LINKQUALITY_ERROR = 25
29
+    #
26 30
     LAST_MSG_WARNING = 6 * 60 * 60
27 31
     LAST_MSG_ERROR = 24 * 60 * 60
28 32
 
@@ -40,6 +44,7 @@ class base(object):
40 44
         self.__state_storage__ = {}
41 45
         #
42 46
         self.battery = None
47
+        self.linkquality = None
43 48
 
44 49
     def __rx__(self, client, userdata, message):
45 50
         try:
@@ -66,6 +71,11 @@ class base(object):
66 71
                 #
67 72
                 if self.MONITORING_BATTERY in payload and message.topic == self.topic:
68 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 80
     def target(self, key, value):
71 81
         tm_t, value_t = self.__target_storage__.get(key, (0, None))
@@ -126,6 +136,18 @@ class base(object):
126 136
                 return self.__nagios_return__(self.MONITORING_BATTERY, nagios.Nagios.WARNING, "Battery level low (%.1f%%)" % self.battery)
127 137
             else:
128 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 152
     def __nagios_return__(self, monitoring_name, status, msg, force=False):
131 153
         tm = time.time()

+ 2
- 0
z_server/z_protocol.py Просмотреть файл

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

Загрузка…
Отмена
Сохранить