check_shelly - wifi implemented
This commit is contained in:
parent
6000cb1f0a
commit
a0a7fd0c7e
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "nagios"]
|
||||
path = nagios
|
||||
url = https://git.mount-mockery.de/pylib/nagios.git
|
13
.vscode/settings.json
vendored
Normal file
13
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"autopep8.args": ["--max-line-length=150"],
|
||||
"[python]": {
|
||||
"python.formatting.provider": "none",
|
||||
"editor.defaultFormatter": "ms-python.autopep8",
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"editor.fontSize": 14,
|
||||
"emmet.includeLanguages": { "django-html": "html" },
|
||||
"python.testing.pytestArgs": ["-v", "--cov", "--cov-report=xml", "__test__"],
|
||||
"python.testing.unittestEnabled": false,
|
||||
"python.testing.pytestEnabled": true
|
||||
}
|
40
check_shelly
Executable file
40
check_shelly
Executable file
@ -0,0 +1,40 @@
|
||||
#!/bin/python3
|
||||
#
|
||||
import argparse
|
||||
import json
|
||||
import nagios
|
||||
import os
|
||||
import urllib.request
|
||||
|
||||
CHECKS = ['wifi']
|
||||
#
|
||||
WIFI_QUALITY_ERROR = -30
|
||||
WIFI_QUALITY_WARNING = -50
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
prog=os.path.basename(__file__),
|
||||
description='Check shelly for nagios monitorin',
|
||||
# epilog='Text at the bottom of help'
|
||||
)
|
||||
parser.add_argument('-H', '--hostname', required=True)
|
||||
parser.add_argument('-c', '--check', choices=CHECKS, required=True)
|
||||
args = parser.parse_args()
|
||||
#
|
||||
n = nagios.Nagios()
|
||||
status = n.UNKNOWN
|
||||
#
|
||||
with urllib.request.urlopen(f"http://{args.hostname}/status") as response:
|
||||
data = json.load(response)
|
||||
#
|
||||
#
|
||||
if args.check == 'wifi':
|
||||
connected = data['wifi_sta']['connected']
|
||||
quality = data['wifi_sta']['rssi']
|
||||
if not connected or quality > WIFI_QUALITY_ERROR:
|
||||
status = n.ERROR
|
||||
elif quality > WIFI_QUALITY_WARNING:
|
||||
status = n.WARNING
|
||||
else:
|
||||
status = n.OK
|
||||
n.exit(status, f"connected: {connected} - quality: {quality}")
|
1
nagios
Submodule
1
nagios
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 3d7f2eca05ebe5fdcf17f9e77e47cc62d326874b
|
Loading…
x
Reference in New Issue
Block a user