|
@@ -6,10 +6,16 @@ import nagios
|
6
|
6
|
import os
|
7
|
7
|
import urllib.request
|
8
|
8
|
|
9
|
|
-CHECKS = ['wifi']
|
|
9
|
+CHECKS = ['wifi', 'mqtt', 'memory', 'filesystem']
|
10
|
10
|
#
|
11
|
11
|
WIFI_QUALITY_ERROR = -30
|
12
|
12
|
WIFI_QUALITY_WARNING = -50
|
|
13
|
+#
|
|
14
|
+RAM_ERROR = .15
|
|
15
|
+RAM_WARNING = .30
|
|
16
|
+#
|
|
17
|
+FS_ERROR = .15
|
|
18
|
+FS_WARNING = .30
|
13
|
19
|
|
14
|
20
|
if __name__ == "__main__":
|
15
|
21
|
parser = argparse.ArgumentParser(
|
|
@@ -37,4 +43,33 @@ if __name__ == "__main__":
|
37
|
43
|
status = n.WARNING
|
38
|
44
|
else:
|
39
|
45
|
status = n.OK
|
40
|
|
- n.exit(status, f"connected: {connected} - quality: {quality}")
|
|
46
|
+ n.exit(status, f"connected: {connected} - quality: {quality} < {WIFI_QUALITY_WARNING} < {WIFI_QUALITY_ERROR}")
|
|
47
|
+ elif args.check == 'mqtt':
|
|
48
|
+ connected = data['mqtt']['connected']
|
|
49
|
+ if not connected:
|
|
50
|
+ status = n.ERROR
|
|
51
|
+ else:
|
|
52
|
+ status = n.OK
|
|
53
|
+ n.exit(status, f"connected: {connected}")
|
|
54
|
+ elif args.check == 'memory':
|
|
55
|
+ ram_total = data['ram_total']
|
|
56
|
+ ram_free = data['ram_free']
|
|
57
|
+ ram_left = ram_free / ram_total
|
|
58
|
+ if ram_left < RAM_ERROR:
|
|
59
|
+ status = n.ERROR
|
|
60
|
+ elif ram_left < RAM_WARNING:
|
|
61
|
+ status = n.WARNING
|
|
62
|
+ else:
|
|
63
|
+ status = n.OK
|
|
64
|
+ n.exit(status, f"ram_left: {ram_left} ({ram_total}) > {RAM_WARNING} > {RAM_ERROR}")
|
|
65
|
+ elif args.check == 'filesystem':
|
|
66
|
+ fs_size = data['fs_size']
|
|
67
|
+ fs_free = data['fs_free']
|
|
68
|
+ fs_left = fs_free / fs_size
|
|
69
|
+ if fs_left < FS_ERROR:
|
|
70
|
+ status = n.ERROR
|
|
71
|
+ elif fs_left < FS_WARNING:
|
|
72
|
+ status = n.WARNING
|
|
73
|
+ else:
|
|
74
|
+ status = n.OK
|
|
75
|
+ n.exit(status, f"fs_left: {fs_left} ({fs_size}) > {FS_WARNING} > {FS_ERROR}")
|