Quellcode durchsuchen

check_shelly - wifi implemented

master
Dirk Alders vor 1 Jahr
Ursprung
Commit
a0a7fd0c7e
4 geänderte Dateien mit 57 neuen und 0 gelöschten Zeilen
  1. 3
    0
      .gitmodules
  2. 13
    0
      .vscode/settings.json
  3. 40
    0
      check_shelly
  4. 1
    0
      nagios

+ 3
- 0
.gitmodules Datei anzeigen

@@ -0,0 +1,3 @@
1
+[submodule "nagios"]
2
+	path = nagios
3
+	url = https://git.mount-mockery.de/pylib/nagios.git

+ 13
- 0
.vscode/settings.json Datei anzeigen

@@ -0,0 +1,13 @@
1
+{
2
+  "autopep8.args": ["--max-line-length=150"],
3
+  "[python]": {
4
+    "python.formatting.provider": "none",
5
+    "editor.defaultFormatter": "ms-python.autopep8",
6
+    "editor.formatOnSave": true
7
+  },
8
+  "editor.fontSize": 14,
9
+  "emmet.includeLanguages": { "django-html": "html" },
10
+  "python.testing.pytestArgs": ["-v", "--cov", "--cov-report=xml", "__test__"],
11
+  "python.testing.unittestEnabled": false,
12
+  "python.testing.pytestEnabled": true
13
+}

+ 40
- 0
check_shelly Datei anzeigen

@@ -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}")

+ 1
- 0
nagios

@@ -0,0 +1 @@
1
+Subproject commit 3d7f2eca05ebe5fdcf17f9e77e47cc62d326874b

Laden…
Abbrechen
Speichern