Projet

Général

Profil

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

root / plugins / router / ag241-adsl @ 0253df6f

Historique | Voir | Annoter | Télécharger (4,09 ko)

1
#!/usr/bin/env ruby
2

    
3
=begin
4

    
5
=head1 NAME
6

    
7
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

    
15
This modem also has some basic SNMP support so you can configure it
16
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
You will need to set up the "virtual node" configuration as detailed
22
for snmp plugins.
23

    
24
=head1 CONFIGURATION
25

    
26
The plugin requires some configuration in /etc/munin/plugin-conf.d/ag241_MODEMADDRESS
27
e.g.
28

    
29
 [ag241_vocume.stargate_*]
30
 env.user admin
31
 env.pass password
32
 #env.port 80
33

    
34
Once you have the above config set you will need to symlink the plugin to
35

    
36
 /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
#%# family=manual
51

    
52
=end
53

    
54
# Require this module, it is part of the standard ruby lib AFAIK
55
require 'net/http'
56

    
57
# default parameters
58
host = nil
59
port = ENV['port'] || 80
60
user = ENV['user'] || 'admin'
61
pass = ENV['pass'] || 'forhax' # don't remember what the default admin password was
62
stat = nil
63

    
64
# Check executable "name" for parameter count
65
params = $0.split('_')
66
if params.size != 3
67
  puts 'Incorrect number of parameters'
68
  exit 1
69
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
  puts 'user = ' + user
78
  puts 'pass = ' + pass
79
  puts 'host = ' + host
80
  puts 'port = ' + port
81
  puts 'stat = ' + stat
82
end
83

    
84
# Dump the graph configuration data
85
if ARGV[0] == 'config'
86
  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
end
108

    
109
# Connect to the webadmin
110
http = Net::HTTP.start(host, port)
111
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
# Make sure we got the page successfully
118
if response.code != '200'
119
  puts 'Getting web page failed:'
120
  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
end
131

    
132
# Apply voodoo regex to the result HTML to get the data we want.
133
case stat
134
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
  puts 'down.value ' + b.to_i.to_s + "\n" + 'up.value ' + c.to_i.to_s
143
  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
  puts 'down.value ' + b.to_i.to_s + "\n" + 'up.value ' + c.to_i.to_s
148
  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
end