root / plugins / router / ag241-adsl @ 6a79efee
Historique | Voir | Annoter | Télécharger (4,09 ko)
| 1 | 7a37bfb1 | Lars Kruse | #!/usr/bin/env ruby |
|---|---|---|---|
| 2 | b0b39b01 | Lars Kruse | |
| 3 | =begin |
||
| 4 | |||
| 5 | 0253df6f | Lars Kruse | =head1 NAME |
| 6 | b0b39b01 | Lars Kruse | |
| 7 | 0253df6f | Lars Kruse | ag241-adsl - retrieve connection statistics from the web admin interface of a Linksys AG241v2 ADSL modem |
| 8 | |||
| 9 | =head1 DESCRIPTION |
||
| 10 | |||
| 11 | Data is extracted from the http://modemaddress/ADSLCStatus.htm page. |
||
| 12 | |||
| 13 | This plugin has only been tested on a Debian testing system. |
||
| 14 | b0b39b01 | Lars Kruse | |
| 15 | This modem also has some basic SNMP support so you can configure it |
||
| 16 | 0253df6f | Lars Kruse | as per the instructions on the munin wiki: |
| 17 | |||
| 18 | http://munin.projects.linpro.no/wiki/Using_SNMP_plugins |
||
| 19 | |||
| 20 | By default the SNMP server is disabled, you can enable it in the web admin. |
||
| 21 | b0b39b01 | Lars Kruse | You will need to set up the "virtual node" configuration as detailed |
| 22 | 0253df6f | Lars Kruse | for snmp plugins. |
| 23 | |||
| 24 | =head1 CONFIGURATION |
||
| 25 | b0b39b01 | Lars Kruse | |
| 26 | 0253df6f | Lars Kruse | The plugin requires some configuration in /etc/munin/plugin-conf.d/ag241_MODEMADDRESS |
| 27 | b0b39b01 | Lars Kruse | e.g. |
| 28 | 0253df6f | Lars Kruse | |
| 29 | [ag241_vocume.stargate_*] |
||
| 30 | env.user admin |
||
| 31 | env.pass password |
||
| 32 | #env.port 80 |
||
| 33 | b0b39b01 | Lars Kruse | |
| 34 | Once you have the above config set you will need to symlink the plugin to |
||
| 35 | |||
| 36 | 0253df6f | Lars Kruse | /etc/munin/plugins/ag241_MODEMADDRESS_syncrate |
| 37 | /etc/munin/plugins/ag241_MODEMADDRESS_attenutation |
||
| 38 | /etc/munin/plugins/ag241_MODEMADDRESS_noise |
||
| 39 | |||
| 40 | Restart munin-node afterwards. |
||
| 41 | |||
| 42 | Hopefully in 20-30mins you will have some nice graphs. |
||
| 43 | |||
| 44 | =head1 AUTHORS |
||
| 45 | |||
| 46 | Copyright (C) 2010 David Leggett |
||
| 47 | |||
| 48 | =head1 MAGIC MARKERS |
||
| 49 | |||
| 50 | dea71d3d | David Leggett | #%# family=manual |
| 51 | |||
| 52 | b0b39b01 | Lars Kruse | =end |
| 53 | |||
| 54 | dea71d3d | David Leggett | # Require this module, it is part of the standard ruby lib AFAIK |
| 55 | require 'net/http' |
||
| 56 | |||
| 57 | b0b39b01 | Lars Kruse | # default parameters |
| 58 | 17f78427 | Lars Kruse | host = nil |
| 59 | dea71d3d | David Leggett | port = ENV['port'] || 80 |
| 60 | user = ENV['user'] || 'admin' |
||
| 61 | b0b39b01 | Lars Kruse | pass = ENV['pass'] || 'forhax' # don't remember what the default admin password was |
| 62 | dea71d3d | David Leggett | stat = nil |
| 63 | |||
| 64 | 8713eb37 | Lars Kruse | # Check executable "name" for parameter count |
| 65 | dea71d3d | David Leggett | params = $0.split('_')
|
| 66 | if params.size != 3 |
||
| 67 | 809639ab | Lars Kruse | puts 'Incorrect number of parameters' |
| 68 | b0b39b01 | Lars Kruse | exit 1 |
| 69 | dea71d3d | David Leggett | end |
| 70 | |||
| 71 | # first param after the plugin name is the host to query |
||
| 72 | # second is the statistic to query |
||
| 73 | host = params[1] |
||
| 74 | stat = params[2] |
||
| 75 | |||
| 76 | unless ENV['debug'].nil? |
||
| 77 | 809639ab | Lars Kruse | puts 'user = ' + user |
| 78 | puts 'pass = ' + pass |
||
| 79 | puts 'host = ' + host |
||
| 80 | puts 'port = ' + port |
||
| 81 | puts 'stat = ' + stat |
||
| 82 | dea71d3d | David Leggett | end |
| 83 | |||
| 84 | # Dump the graph configuration data |
||
| 85 | if ARGV[0] == 'config' |
||
| 86 | b0b39b01 | Lars Kruse | puts 'host_name ' + host |
| 87 | puts 'graph_category network' |
||
| 88 | |||
| 89 | case stat |
||
| 90 | when 'syncrate' |
||
| 91 | puts 'graph_info This graph shows the ADSL line sync rate.' |
||
| 92 | puts 'graph_title ADSL line sync rate' |
||
| 93 | puts 'graph_vlabel connection rate bits / second' |
||
| 94 | puts 'graph_args --base 1000 -l 0 ' |
||
| 95 | when 'attenuation' |
||
| 96 | puts 'graph_info This graph shows the ADSL line attenuation.' |
||
| 97 | puts 'graph_title ADSL line attenuation' |
||
| 98 | puts 'graph_vlabel attenuation dB' |
||
| 99 | when 'margin', 'noise' |
||
| 100 | puts 'graph_info This graph shows the ADSL SNR margin.' |
||
| 101 | puts 'graph_title ADSL line SNR margin' |
||
| 102 | puts 'graph_vlabel noise margin dB' |
||
| 103 | end |
||
| 104 | puts 'down.label downstream' |
||
| 105 | puts 'up.label upstream' |
||
| 106 | exit 0 |
||
| 107 | dea71d3d | David Leggett | end |
| 108 | |||
| 109 | # Connect to the webadmin |
||
| 110 | b0b39b01 | Lars Kruse | http = Net::HTTP.start(host, port) |
| 111 | dea71d3d | David Leggett | req = Net::HTTP::Get.new('/ADSLCStatus.htm')
|
| 112 | # send the login info |
||
| 113 | req.basic_auth user, pass |
||
| 114 | response = http.request(req) |
||
| 115 | s = response.body |
||
| 116 | |||
| 117 | b0b39b01 | Lars Kruse | # Make sure we got the page successfully |
| 118 | dea71d3d | David Leggett | if response.code != '200' |
| 119 | 809639ab | Lars Kruse | puts 'Getting web page failed:' |
| 120 | b0b39b01 | Lars Kruse | case response.code |
| 121 | when '401' |
||
| 122 | puts 'Probably because the username and password are incorrect' |
||
| 123 | # Looks like the modem response with 200 when you try to access a page that does not exist >_> |
||
| 124 | # when '404' |
||
| 125 | # puts 'Looks like the page this plugin needs isn\'t available...' |
||
| 126 | # puts 'Check your modem make/model/version' |
||
| 127 | end |
||
| 128 | puts s |
||
| 129 | exit 1 |
||
| 130 | dea71d3d | David Leggett | end |
| 131 | |||
| 132 | # Apply voodoo regex to the result HTML to get the data we want. |
||
| 133 | case stat |
||
| 134 | b0b39b01 | Lars Kruse | when 'syncrate' |
| 135 | a = s.scan(/.*share\.curstate.*\n.*share\.downstr[^0-9]*([0-9]+).*share\.upstr[^0-9]*([0-9]+).*$/) |
||
| 136 | b, c = a[0] |
||
| 137 | puts 'down.value ' + (b.to_i * 1000).to_s + "\n" + 'up.value ' + (c.to_i * 1000).to_s |
||
| 138 | exit 0 |
||
| 139 | when 'attenuation' |
||
| 140 | a = s.scan(/.*share\.lineatt.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/) |
||
| 141 | b, c = a[0] |
||
| 142 | 809639ab | Lars Kruse | puts 'down.value ' + b.to_i.to_s + "\n" + 'up.value ' + c.to_i.to_s |
| 143 | b0b39b01 | Lars Kruse | exit 0 |
| 144 | when 'margin', 'noise' |
||
| 145 | a = s.scan(/.*share\.noise.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/) |
||
| 146 | b, c = a[0] |
||
| 147 | 809639ab | Lars Kruse | puts 'down.value ' + b.to_i.to_s + "\n" + 'up.value ' + c.to_i.to_s |
| 148 | b0b39b01 | Lars Kruse | exit 0 |
| 149 | else |
||
| 150 | puts 'Statistic ' + stat.to_s + ' not known, would you like me to fabricate it for you?' |
||
| 151 | exit 1 |
||
| 152 | dea71d3d | David Leggett | end |
