|
@@ -0,0 +1,40 @@
|
|
1
|
+#!/bin/python3
|
|
2
|
+#
|
|
3
|
+import argparse
|
|
4
|
+import json
|
|
5
|
+import nagios
|
|
6
|
+import os
|
|
7
|
+import urllib.request
|
|
8
|
+
|
|
9
|
+CHECKS = ['wifi']
|
|
10
|
+#
|
|
11
|
+WIFI_QUALITY_ERROR = -30
|
|
12
|
+WIFI_QUALITY_WARNING = -50
|
|
13
|
+
|
|
14
|
+if __name__ == "__main__":
|
|
15
|
+ parser = argparse.ArgumentParser(
|
|
16
|
+ prog=os.path.basename(__file__),
|
|
17
|
+ description='Check shelly for nagios monitorin',
|
|
18
|
+ # epilog='Text at the bottom of help'
|
|
19
|
+ )
|
|
20
|
+ parser.add_argument('-H', '--hostname', required=True)
|
|
21
|
+ parser.add_argument('-c', '--check', choices=CHECKS, required=True)
|
|
22
|
+ args = parser.parse_args()
|
|
23
|
+ #
|
|
24
|
+ n = nagios.Nagios()
|
|
25
|
+ status = n.UNKNOWN
|
|
26
|
+ #
|
|
27
|
+ with urllib.request.urlopen(f"http://{args.hostname}/status") as response:
|
|
28
|
+ data = json.load(response)
|
|
29
|
+ #
|
|
30
|
+ #
|
|
31
|
+ if args.check == 'wifi':
|
|
32
|
+ connected = data['wifi_sta']['connected']
|
|
33
|
+ quality = data['wifi_sta']['rssi']
|
|
34
|
+ if not connected or quality > WIFI_QUALITY_ERROR:
|
|
35
|
+ status = n.ERROR
|
|
36
|
+ elif quality > WIFI_QUALITY_WARNING:
|
|
37
|
+ status = n.WARNING
|
|
38
|
+ else:
|
|
39
|
+ status = n.OK
|
|
40
|
+ n.exit(status, f"connected: {connected} - quality: {quality}")
|