Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / router / ag241-adsl @ 5061ef1d

Historique | Voir | Annoter | Télécharger (3,97 ko)

1
#!/usr/bin/env ruby
2

    
3
=begin
4

    
5
munin plugin to retrieve connection statistics from the web admin interface
6
on a Linksys AG241v2 ADSL modem
7
Makes use of the http://modemaddress/ADSLCStatus.htm page
8

    
9
This plugin has only been tested on a Debian testing system
10

    
11
This modem also has some basic SNMP support so you can configure it
12
as per the instructions on the munin wiki
13
http://munin.projects.linpro.no/wiki/Using_SNMP_plugins
14
By default the SNMP server is disabled, you can enable it in the web admin
15
You will need to set up the "virtual node" configuration as detailed
16
for snmp plugins
17

    
18
Plugin will require some configuration in /etc/munin/plugin-conf.d/ag241_MODEMADDRESS
19
e.g.
20
[ag241_vocume.stargate_*]
21
env.user admin
22
env.pass password
23
#env.port 80
24

    
25
Once you have the above config set you will need to symlink the plugin to
26
/etc/munin/plugins/ag241_MODEMADDRESS_syncrate
27
/etc/munin/plugins/ag241_MODEMADDRESS_attenutation
28
/etc/munin/plugins/ag241_MODEMADDRESS_noise
29
now restart munin-node.
30
hopefully in 20-30mins you will have some nice graphs
31

    
32
Some magical munin foo...
33
#%# family=manual
34
#%# capabilities=
35

    
36
=end
37

    
38
# Require this module, it is part of the standard ruby lib AFAIK
39
require 'net/http'
40

    
41
# default parameters
42
host = nil
43
port = ENV['port'] || 80
44
user = ENV['user'] || 'admin'
45
pass = ENV['pass'] || 'forhax' # don't remember what the default admin password was
46
stat = nil
47

    
48
# Check executable "name" for parameter count
49
params = $0.split('_')
50
if params.size != 3
51
  puts 'Incorrect number of parameters'
52
  exit 1
53
end
54

    
55
# first param after the plugin name is the host to query
56
# second is the statistic to query
57
host = params[1]
58
stat = params[2]
59

    
60
unless ENV['debug'].nil?
61
  puts 'user = ' + user
62
  puts 'pass = ' + pass
63
  puts 'host = ' + host
64
  puts 'port = ' + port
65
  puts 'stat = ' + stat
66
end
67

    
68
# Dump the graph configuration data
69
if ARGV[0] == 'config'
70
  puts 'host_name ' + host
71
  puts 'graph_category network'
72

    
73
  case stat
74
  when 'syncrate'
75
    puts 'graph_info This graph shows the ADSL line sync rate.'
76
    puts 'graph_title ADSL line sync rate'
77
    puts 'graph_vlabel connection rate bits / second'
78
    puts 'graph_args --base 1000 -l 0 '
79
  when 'attenuation'
80
    puts 'graph_info This graph shows the ADSL line attenuation.'
81
    puts 'graph_title ADSL line attenuation'
82
    puts 'graph_vlabel attenuation dB'
83
  when 'margin', 'noise'
84
    puts 'graph_info This graph shows the ADSL SNR margin.'
85
    puts 'graph_title ADSL line SNR margin'
86
    puts 'graph_vlabel noise margin dB'
87
  end
88
  puts 'down.label downstream'
89
  puts 'up.label upstream'
90
  exit 0
91
end
92

    
93
# Connect to the webadmin
94
http = Net::HTTP.start(host, port)
95
req = Net::HTTP::Get.new('/ADSLCStatus.htm')
96
# send the login info
97
req.basic_auth user, pass
98
response = http.request(req)
99
s = response.body
100

    
101
# Make sure we got the page successfully
102
if response.code != '200'
103
  puts 'Getting web page failed:'
104
  case response.code
105
  when '401'
106
    puts 'Probably because the username and password are incorrect'
107
    # Looks like the modem response with 200 when you try to access a page that does not exist >_>
108
    # when '404'
109
    #	puts 'Looks like the page this plugin needs isn\'t available...'
110
    #	puts 'Check your modem make/model/version'
111
  end
112
  puts s
113
  exit 1
114
end
115

    
116
# Apply voodoo regex to the result HTML to get the data we want.
117
case stat
118
when 'syncrate'
119
  a = s.scan(/.*share\.curstate.*\n.*share\.downstr[^0-9]*([0-9]+).*share\.upstr[^0-9]*([0-9]+).*$/)
120
  b, c = a[0]
121
  puts 'down.value ' + (b.to_i * 1000).to_s + "\n" + 'up.value ' + (c.to_i * 1000).to_s
122
  exit 0
123
when 'attenuation'
124
  a = s.scan(/.*share\.lineatt.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/)
125
  b, c = a[0]
126
  puts 'down.value ' + b.to_i.to_s + "\n" + 'up.value ' + c.to_i.to_s
127
  exit 0
128
when 'margin', 'noise'
129
  a = s.scan(/.*share\.noise.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/)
130
  b, c = a[0]
131
  puts 'down.value ' + b.to_i.to_s + "\n" + 'up.value ' + c.to_i.to_s
132
  exit 0
133
else
134
  puts 'Statistic ' + stat.to_s + ' not known, would you like me to fabricate it for you?'
135
  exit 1
136
end