comparison adslstats.py @ 4:f50214bca1ae

Update for Billion 7700NR2
author Daniel O'Connor <darius@dons.net.au>
date Fri, 07 Feb 2014 20:35:59 +1030
parents a795b6cd8b1a
children 072489c80c51
comparison
equal deleted inserted replaced
1:a795b6cd8b1a 4:f50214bca1ae
67 opts.add_option('-b', '--base', action="store", default="/home/darius/projects/adslstats/adslstats", 67 opts.add_option('-b', '--base', action="store", default="/home/darius/projects/adslstats/adslstats",
68 help="Base directory for RRD & PNGs") 68 help="Base directory for RRD & PNGs")
69 69
70 (options, args) = opts.parse_args() 70 (options, args) = opts.parse_args()
71 71
72 statsurl = "http://%s/adsl.asp" % (options.name) 72 statsurl = "http://%s/statsadsl.html" % (options.name)
73 rrdname = "%s.rrd" % (options.base) 73 rrdname = "%s.rrd" % (options.base)
74 graphbasename = options.base 74 graphbasename = options.base
75 75
76 matchnum = re.compile('([0-9]+(\.[0-9]+)?)') 76 matchnum = re.compile('([0-9]+(\.[0-9]+)?)')
77 statsdict = { 77 statsdict = {
78 7 : 'Upstream', 78 3 : 'Status:',
79 8 : 'Downstream', 79 8 : 'SNR Margin (0.1 dB):',
80 9 : 'Noise Margin (Upstream)', 80 9 : 'Attenuation (0.1 dB):',
81 10 : 'Noise Margin (Downstream)', 81 14 : 'Rate (Kbps):',
82 11 : 'Attenuation (Upstream)', 82 }
83 12 : 'Attenuation (Downstream)' }
84
85 83
86 class ADSLStats(object): 84 class ADSLStats(object):
87 def __str__(self): 85 def __str__(self):
88 return """Line Rate - Up: %d kbits, Down %d kbits 86 return """Line Rate - Up: %d kbits, Down %d kbits
89 Noise Margin - Up: %.1f dB, Down %.1f dB 87 Noise Margin - Up: %.1f dB, Down %.1f dB
101 def getstats(f): 99 def getstats(f):
102 s = BeautifulSoup(f) 100 s = BeautifulSoup(f)
103 a = s.findAll('tr') 101 a = s.findAll('tr')
104 102
105 for i in statsdict: 103 for i in statsdict:
106 assert a[i].td.contents[0].contents[0] == statsdict[i] 104 assert a[i].td.contents[0] == statsdict[i]
107 105
108 stats = ADSLStats() 106 stats = ADSLStats()
109 107
110 # Check if the modem is offline 108 # Check if the modem is offline
111 if a[9].td.findNext('td').contents[0].contents[0].find('N/A') != -1: 109 if a[3].td.contents[0] != 'Up':
112 return None 110 return None
113 stats.upstream = cleannum(a[7].td.findNext('td').contents[0].contents[0]) # kbits 111
114 stats.downstream = cleannum(a[8].td.findNext('td').contents[0].contents[0]) # kbits 112 # dB
115 stats.nmup = cleannum(a[9].td.findNext('td').contents[0].contents[0]) # dB 113 stats.nmdown = float(a[8].td.findNext('td').contents[0]) / 10.0
116 stats.nmdown = cleannum(a[10].td.findNext('td').contents[0].contents[0]) # dB 114 stats.nmup = float(a[8].td.findNext('td').findNext('td').contents[0]) / 10.0
117 stats.attenup = cleannum(a[11].td.findNext('td').contents[0].contents[0]) # dB 115 stats.attendown = float(a[9].td.findNext('td').contents[0]) / 10.0
118 stats.attendown = cleannum(a[12].td.findNext('td').contents[0].contents[0]) # dB 116 stats.attenup = float(a[9].td.findNext('td').findNext('td').contents[0]) / 10.0
117 # kBit
118 stats.upstream = float(a[14].td.findNext('td').contents[0]) / 10.0
119 stats.downstream = float(a[14].td.findNext('td').findNext('td').contents[0]) / 10.0
119 120
120 return stats 121 return stats
121 122
122 # Setup RRD 123 # Setup RRD
123 # We expect data to be logged every 5 minutes 124 # We expect data to be logged every 5 minutes