-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_speedport
executable file
·47 lines (40 loc) · 1.38 KB
/
check_speedport
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import argparse
import requests
from influxdb import InfluxDBClient
from influxdb.exceptions import InfluxDBServerError, InfluxDBClientError
url = 'http://[ROUTER_IP]/data/Status.json'
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Accept-Language': 'en'}
parser = argparse.ArgumentParser(description='Read Speedport router data.')
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-w', '--write', action='store_true')
args = parser.parse_args()
try:
r = requests.get(url, headers=headers)
except requests.exceptions.RequestException as e:
exit(2)
data = {}
if r.content.decode('utf-8').__contains__("login.html"):
print('Router is not supported')
exit(4)
if r.status_code == requests.codes.ok:
j = r.json()
for l in j:
if args.verbose:
print(l['varid'], ':', l['varvalue'])
data[l['varid']] = l['varvalue']
# send to influxDB
if args.write:
d = [{
"measurement": "speedport_data",
"fields": data
}]
try:
client = InfluxDBClient(host='127.0.0.1', port=8086, database='speedport')
client.write_points(d)
except (InfluxDBClientError, InfluxDBServerError):
print("Error writing to InfluxDB")
exit(3)
if data['dsl_link_status'] == 'online':
exit(0)
exit(1)