root / plugins / network / arris-tm502g_ @ 942bda31
Historique | Voir | Annoter | Télécharger (2,62 ko)
| 1 | d8ef1a40 | Kenyon Ralph | #!/usr/bin/env python3 |
|---|---|---|---|
| 2 | # -*- python -*- |
||
| 3 | |||
| 4 | # This plugin graphs the following values of the ARRIS TM502G cable |
||
| 5 | # modem: |
||
| 6 | # |
||
| 7 | # * upstream and downstream powers |
||
| 8 | # * downstream signal-to-noise ratio |
||
| 9 | # |
||
| 10 | # The values are retrieved from the cable modem's status web pages at |
||
| 11 | # 192.168.100.1. So, this plugin must be installed on a munin node |
||
| 12 | # which can access those pages. |
||
| 13 | # |
||
| 14 | # Symlink this plugin into the node's plugins directory (like |
||
| 15 | # /etc/munin/plugins) as arris-tm502g_power for the powers, and |
||
| 16 | # arris-tm502g_snr for the SNR. |
||
| 17 | # |
||
| 18 | # Author: Kenyon Ralph <kenyon@kenyonralph.com> |
||
| 19 | # |
||
| 20 | # The latest version of this plugin can be found in the munin contrib |
||
| 21 | # repository at https://github.com/munin-monitoring/contrib. Issues |
||
| 22 | # with this plugin may be reported there. Patches accepted through the |
||
| 23 | # normal github process of forking the repository and submitting a |
||
| 24 | # pull request with your commits. |
||
| 25 | |||
| 26 | import html.parser |
||
| 27 | import os |
||
| 28 | import urllib.request |
||
| 29 | import sys |
||
| 30 | |||
| 31 | plugin_name=list(os.path.split(sys.argv[0]))[1] |
||
| 32 | plugin_var=plugin_name.split('_', 1)[-1]
|
||
| 33 | |||
| 34 | if len(sys.argv) == 2 and sys.argv[1] == 'config': |
||
| 35 | if plugin_var == 'power': |
||
| 36 | print('graph_title ARRIS Cable Modem Power')
|
||
| 37 | print('graph_vlabel Signal Strength (dBmV)')
|
||
| 38 | print('graph_info This graph shows the downstream and upstream power reported by an ARRIS TM502G cable modem.')
|
||
| 39 | print('downstream.label Downstream Power (dBmV)')
|
||
| 40 | print('upstream.label Upstream Power (dBmV)')
|
||
| 41 | if plugin_var == 'snr': |
||
| 42 | print('graph_title ARRIS Cable Modem SNR')
|
||
| 43 | print('graph_vlabel Signal-to-Noise Ratio (dB)')
|
||
| 44 | print('graph_info This graph shows the downstream signal-to-noise ratio reported by an ARRIS TM502G cable modem.')
|
||
| 45 | print('snr.label Signal-to-Noise Ratio (dB)')
|
||
| 46 | print('graph_category network')
|
||
| 47 | sys.exit(0) |
||
| 48 | |||
| 49 | class ArrisHTMLParser(html.parser.HTMLParser): |
||
| 50 | stats = list() |
||
| 51 | down_power = 'U' |
||
| 52 | up_power = 'U' |
||
| 53 | snr = 'U' |
||
| 54 | def handle_data(self, data): |
||
| 55 | data = data.strip() |
||
| 56 | if data != '' and 'dB' in data: |
||
| 57 | self.stats.append(data) |
||
| 58 | def done(self): |
||
| 59 | """Call this when done feeding the HTML page to the parser.""" |
||
| 60 | self.down_power = self.stats[0].split()[0] |
||
| 61 | self.snr = self.stats[1].split()[0] |
||
| 62 | self.up_power = self.stats[2].split()[0] |
||
| 63 | |||
| 64 | page = urllib.request.urlopen("http://192.168.100.1/")
|
||
| 65 | parser = ArrisHTMLParser() |
||
| 66 | for line in page: |
||
| 67 | parser.feed(line.decode()) |
||
| 68 | parser.done() |
||
| 69 | |||
| 70 | if plugin_var == 'power': |
||
| 71 | print('downstream.value ' + parser.down_power)
|
||
| 72 | print('upstream.value ' + parser.up_power)
|
||
| 73 | sys.exit(0) |
||
| 74 | |||
| 75 | if plugin_var == 'snr': |
||
| 76 | print('snr.value ' + parser.snr)
|
||
| 77 | sys.exit(0) |
