root / plugins / router / arris-tm502g_ @ 7b078749
Historique | Voir | Annoter | Télécharger (2,93 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 | 6f0db08c | Kenyon Ralph | # Copyright © 2013 Kenyon Ralph <kenyon@kenyonralph.com> |
| 19 | d8ef1a40 | Kenyon Ralph | # |
| 20 | c29d25a8 | Kenyon Ralph | # This program is free software. It comes without any warranty, to the |
| 21 | # extent permitted by applicable law. You can redistribute it and/or |
||
| 22 | # modify it under the terms of the Do What The Fuck You Want To Public |
||
| 23 | # License, Version 2, as published by Sam Hocevar. See |
||
| 24 | 6f0db08c | Kenyon Ralph | # http://www.wtfpl.net/ for more details. |
| 25 | c29d25a8 | Kenyon Ralph | # |
| 26 | d8ef1a40 | Kenyon Ralph | # The latest version of this plugin can be found in the munin contrib |
| 27 | # repository at https://github.com/munin-monitoring/contrib. Issues |
||
| 28 | # with this plugin may be reported there. Patches accepted through the |
||
| 29 | # normal github process of forking the repository and submitting a |
||
| 30 | # pull request with your commits. |
||
| 31 | |||
| 32 | import html.parser |
||
| 33 | import os |
||
| 34 | import urllib.request |
||
| 35 | import sys |
||
| 36 | |||
| 37 | plugin_name=list(os.path.split(sys.argv[0]))[1] |
||
| 38 | plugin_var=plugin_name.split('_', 1)[-1]
|
||
| 39 | |||
| 40 | if len(sys.argv) == 2 and sys.argv[1] == 'config': |
||
| 41 | if plugin_var == 'power': |
||
| 42 | print('graph_title ARRIS Cable Modem Power')
|
||
| 43 | print('graph_vlabel Signal Strength (dBmV)')
|
||
| 44 | print('graph_info This graph shows the downstream and upstream power reported by an ARRIS TM502G cable modem.')
|
||
| 45 | print('downstream.label Downstream Power (dBmV)')
|
||
| 46 | print('upstream.label Upstream Power (dBmV)')
|
||
| 47 | if plugin_var == 'snr': |
||
| 48 | print('graph_title ARRIS Cable Modem SNR')
|
||
| 49 | print('graph_vlabel Signal-to-Noise Ratio (dB)')
|
||
| 50 | print('graph_info This graph shows the downstream signal-to-noise ratio reported by an ARRIS TM502G cable modem.')
|
||
| 51 | print('snr.label Signal-to-Noise Ratio (dB)')
|
||
| 52 | print('graph_category network')
|
||
| 53 | sys.exit(0) |
||
| 54 | |||
| 55 | class ArrisHTMLParser(html.parser.HTMLParser): |
||
| 56 | stats = list() |
||
| 57 | down_power = 'U' |
||
| 58 | up_power = 'U' |
||
| 59 | snr = 'U' |
||
| 60 | def handle_data(self, data): |
||
| 61 | data = data.strip() |
||
| 62 | if data != '' and 'dB' in data: |
||
| 63 | self.stats.append(data) |
||
| 64 | def done(self): |
||
| 65 | """Call this when done feeding the HTML page to the parser.""" |
||
| 66 | self.down_power = self.stats[0].split()[0] |
||
| 67 | self.snr = self.stats[1].split()[0] |
||
| 68 | self.up_power = self.stats[2].split()[0] |
||
| 69 | |||
| 70 | page = urllib.request.urlopen("http://192.168.100.1/")
|
||
| 71 | parser = ArrisHTMLParser() |
||
| 72 | for line in page: |
||
| 73 | parser.feed(line.decode()) |
||
| 74 | parser.done() |
||
| 75 | |||
| 76 | if plugin_var == 'power': |
||
| 77 | print('downstream.value ' + parser.down_power)
|
||
| 78 | print('upstream.value ' + parser.up_power)
|
||
| 79 | sys.exit(0) |
||
| 80 | |||
| 81 | if plugin_var == 'snr': |
||
| 82 | print('snr.value ' + parser.snr)
|
||
| 83 | sys.exit(0) |
