Projet

Général

Profil

Révision b0b39b01

IDb0b39b018e200cd0b771675fd0a6489f6ee9f045
Parent 26c29daa
Enfant 809639ab

Ajouté par Lars Kruse il y a plus de 5 ans

Ruby plugins: apply style changes as suggested by "rubocop --fix-layout"

Voir les différences:

plugins/router/ag241-adsl
1 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...
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...
31 33
#%# family=manual
32 34
#%# capabilities=
33 35

  
36
=end
37

  
38

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

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

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

  
51 56
# first param after the plugin name is the host to query
......
54 59
stat = params[2]
55 60

  
56 61
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
  puts "user = " + user
63
  puts "pass = " + pass
64
  puts "host = " + host
65
  puts "port = " + port
66
  puts "stat = " + stat
62 67
end
63 68

  
64 69
# Dump the graph configuration data
65 70
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
71
  puts 'host_name ' + host
72
  puts 'graph_category network'
73

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

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

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

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

Formats disponibles : Unified diff