1
0
Files
nagios-plugins/check_clients.py
2018-05-03 20:27:22 +02:00

31 lines
710 B
Python
Executable File

#!/usr/bin/python3
import json
from urllib.request import urlopen
from pprint import pprint
import sys
JSON_URL = "https://netinfo.freifunk-stuttgart.de/json/alfred-json-159.json"
if len(sys.argv) != 2:
print("UNKNOWN: Invalid arguments "+sys.argv[0]+" <node mac>")
exit(3)
node_mac = sys.argv[1]
response = urlopen(JSON_URL)
data = json.loads(response.read().decode("utf-8"))
node = {}
try:
node = data[node_mac]
except KeyError as e:
print("CRITICAL: Node not found: "+str(e))
exit(2)
performance_data = ""
for key,value in node['clients'].items():
performance_data += "|"+str(key)+"="+str(value)+"\n"
print("OK - %d Clients"%node['clients']['total']+performance_data)
exit(0)