Projet

Général

Profil

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

root / plugins / router / ag241-adsl @ 17f78427

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

1
#!/usr/bin/env ruby
2
# munin plugin to retrieve connection statistics from the web admin interface
3
# on a Linksys AG241v2 ADSL modem
4
# Makes use of the http://modemaddress/ADSLCStatus.htm page
5

    
6
#This plugin has only been tested on a Debian testing system
7

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

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

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

    
29

    
30
#Some magical munin foo...
31
#%# family=manual
32
#%# capabilities=
33

    
34
# Require this module, it is part of the standard ruby lib AFAIK
35
require 'net/http'
36

    
37
#default parameters
38
host = nil
39
port = ENV['port'] || 80
40
user = ENV['user'] || 'admin'
41
pass = ENV['pass'] || 'forhax' #dont remember what the default admin password was
42
stat = nil
43

    
44
# Check executeable "name" for parameter count
45
params = $0.split('_')
46
if params.size != 3
47
	puts "Incorrect number of parameters"
48
	exit 1
49
end
50

    
51
# first param after the plugin name is the host to query
52
# second is the statistic to query
53
host = params[1]
54
stat = params[2]
55

    
56
unless ENV['debug'].nil?
57
	puts "user = "+ user
58
	puts "pass = "+ pass
59
	puts "host = "+ host
60
	puts "port = "+ port
61
	puts "stat = "+ stat
62
end
63

    
64
# Dump the graph configuration data
65
if ARGV[0] == 'config'
66
	puts 'host_name ' + host
67
	puts 'graph_category network'
68

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

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

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

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