-
Notifications
You must be signed in to change notification settings - Fork 0
/
arris_modem.py
executable file
·86 lines (67 loc) · 2.63 KB
/
arris_modem.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Arris cable modem plugin for collectd
This plugin scrapes upstream/downstream channel information from an Arris cable modem status page.
Author: Jacob Kupersmith <jake@jkup.org>
URL: https://github.com/jakup/collectd-surfboard
Last Updated: 2018-05-28
"""
import collectd
import requests
from BeautifulSoup import BeautifulSoup
HOST = ''
URL = 'http://192.168.100.1'
def config_func(config):
host_set = False
url_set = False
for node in config.children:
key = node.key.lower()
value = node.values[0]
if key == 'host':
global HOST
HOST = value
host_set = True
elif key == 'url':
global URL
URL = value
url_set = True
else:
collectd.info('arris_modem plugin: unknown config key "%s"' % key)
if host_set:
collectd.info('arris_modem plugin: Using overridden host %s' % HOST)
if url_set:
collectd.info('arris_modem plugin: Using overridden url %s' % URL)
else:
collectd.info('arris_modem plugin: Using default url %s' % URL)
def read_func():
val = collectd.Values(host=HOST, plugin='arris_modem')
resp = requests.get('%s/cgi-bin/status' % URL)
soup = BeautifulSoup(resp.content)
for table in soup.findAll('table'):
try:
table_name = table.tr.th.text
except:
continue
if table_name == 'Downstream Bonded Channels':
for r in table.findAll('tr')[2:]:
row = map(lambda x: x.text, r.findAll('td'))
freq_hz = float(row[4].split(' ')[0]) * 1000000.0 # 0.0 MHz
power = float(row[5].split(' ')[0]) # 0.0 dBmV
snr = float(row[6].split(' ')[0]) # 0.0 dB
corrected = int(row[7])
uncorrectables = int(row[8])
val.dispatch(type='ds',
type_instance='ch%s' % row[3],
values=[freq_hz, power, snr, corrected, uncorrectables])
elif table_name == 'Upstream Bonded Channels':
for r in table.findAll('tr')[2:]:
row = map(lambda x: x.text, r.findAll('td'))
symrate = float(row[4].split(' ')[0]) # 0 kSym/s
freq_hz = float(row[5].split(' ')[0]) * 1000000.0 # 0.0 MHz
power = float(row[6].split(' ')[0]) # 0.0 dBmV
val.dispatch(type='us',
type_instance='ch%s' % row[3],
values=[symrate, freq_hz, power])
collectd.register_config(config_func)
collectd.register_read(read_func)