mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Ruby plugins: apply style changes as suggested by "rubocop --fix-layout"
This commit is contained in:
parent
26c29daa2b
commit
b0b39b018e
30 changed files with 1447 additions and 1384 deletions
|
@ -1,51 +1,56 @@
|
|||
#!/usr/bin/env ruby
|
||||
# munin plugin to retrieve connection statistics from the web admin interface
|
||||
# on a Linksys AG241v2 ADSL modem
|
||||
# Makes use of the http://modemaddress/ADSLCStatus.htm page
|
||||
|
||||
#This plugin has only been tested on a Debian testing system
|
||||
=begin
|
||||
|
||||
# This modem also has some basic SNMP support so you can configure it
|
||||
# as per the instructions on the munin wiki
|
||||
# http://munin.projects.linpro.no/wiki/Using_SNMP_plugins
|
||||
# By default the SNMP server is disabled, you can enable it in the web admin
|
||||
# You will need to set up the "virtual node" configuration as detailed
|
||||
# for snmp plugins
|
||||
munin plugin to retrieve connection statistics from the web admin interface
|
||||
on a Linksys AG241v2 ADSL modem
|
||||
Makes use of the http://modemaddress/ADSLCStatus.htm page
|
||||
|
||||
# Plugin will require some configuration in /etc/munin/plugin-conf.d/ag241_MODEMADDRESS
|
||||
# e.g.
|
||||
# [ag241_vocume.stargate_*]
|
||||
# env.user admin
|
||||
# env.pass password
|
||||
# #env.port 80
|
||||
This plugin has only been tested on a Debian testing system
|
||||
|
||||
# Once you have the above config set you will need to symlink the plugin to
|
||||
# /etc/munin/plugins/ag241_MODEMADDRESS_syncrate
|
||||
# /etc/munin/plugins/ag241_MODEMADDRESS_attenutation
|
||||
# /etc/munin/plugins/ag241_MODEMADDRESS_noise
|
||||
# now restart munin-node.
|
||||
# hopefully in 20-30mins you will have some nice graphs
|
||||
This modem also has some basic SNMP support so you can configure it
|
||||
as per the instructions on the munin wiki
|
||||
http://munin.projects.linpro.no/wiki/Using_SNMP_plugins
|
||||
By default the SNMP server is disabled, you can enable it in the web admin
|
||||
You will need to set up the "virtual node" configuration as detailed
|
||||
for snmp plugins
|
||||
|
||||
Plugin will require some configuration in /etc/munin/plugin-conf.d/ag241_MODEMADDRESS
|
||||
e.g.
|
||||
[ag241_vocume.stargate_*]
|
||||
env.user admin
|
||||
env.pass password
|
||||
#env.port 80
|
||||
|
||||
#Some magical munin foo...
|
||||
Once you have the above config set you will need to symlink the plugin to
|
||||
/etc/munin/plugins/ag241_MODEMADDRESS_syncrate
|
||||
/etc/munin/plugins/ag241_MODEMADDRESS_attenutation
|
||||
/etc/munin/plugins/ag241_MODEMADDRESS_noise
|
||||
now restart munin-node.
|
||||
hopefully in 20-30mins you will have some nice graphs
|
||||
|
||||
Some magical munin foo...
|
||||
#%# family=manual
|
||||
#%# capabilities=
|
||||
|
||||
=end
|
||||
|
||||
|
||||
# Require this module, it is part of the standard ruby lib AFAIK
|
||||
require 'net/http'
|
||||
|
||||
#default parameters
|
||||
# default parameters
|
||||
host = nil
|
||||
port = ENV['port'] || 80
|
||||
user = ENV['user'] || 'admin'
|
||||
pass = ENV['pass'] || 'forhax' #don't remember what the default admin password was
|
||||
pass = ENV['pass'] || 'forhax' # don't remember what the default admin password was
|
||||
stat = nil
|
||||
|
||||
# Check executable "name" for parameter count
|
||||
params = $0.split('_')
|
||||
if params.size != 3
|
||||
puts "Incorrect number of parameters"
|
||||
exit 1
|
||||
puts "Incorrect number of parameters"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# first param after the plugin name is the host to query
|
||||
|
@ -54,79 +59,79 @@ host = params[1]
|
|||
stat = params[2]
|
||||
|
||||
unless ENV['debug'].nil?
|
||||
puts "user = "+ user
|
||||
puts "pass = "+ pass
|
||||
puts "host = "+ host
|
||||
puts "port = "+ port
|
||||
puts "stat = "+ stat
|
||||
puts "user = " + user
|
||||
puts "pass = " + pass
|
||||
puts "host = " + host
|
||||
puts "port = " + port
|
||||
puts "stat = " + stat
|
||||
end
|
||||
|
||||
# Dump the graph configuration data
|
||||
if ARGV[0] == 'config'
|
||||
puts 'host_name ' + host
|
||||
puts 'graph_category network'
|
||||
puts 'host_name ' + host
|
||||
puts 'graph_category network'
|
||||
|
||||
case stat
|
||||
when 'syncrate'
|
||||
puts 'graph_info This graph shows the ADSL line sync rate.'
|
||||
puts 'graph_title ADSL line sync rate'
|
||||
puts 'graph_vlabel connection rate bits / second'
|
||||
puts 'graph_args --base 1000 -l 0 '
|
||||
when 'attenuation'
|
||||
puts 'graph_info This graph shows the ADSL line attenuation.'
|
||||
puts 'graph_title ADSL line attenuation'
|
||||
puts 'graph_vlabel attenuation dB'
|
||||
when 'margin','noise'
|
||||
puts 'graph_info This graph shows the ADSL SNR margin.'
|
||||
puts 'graph_title ADSL line SNR margin'
|
||||
puts 'graph_vlabel noise margin dB'
|
||||
end
|
||||
puts 'down.label downstream'
|
||||
puts 'up.label upstream'
|
||||
exit 0
|
||||
case stat
|
||||
when 'syncrate'
|
||||
puts 'graph_info This graph shows the ADSL line sync rate.'
|
||||
puts 'graph_title ADSL line sync rate'
|
||||
puts 'graph_vlabel connection rate bits / second'
|
||||
puts 'graph_args --base 1000 -l 0 '
|
||||
when 'attenuation'
|
||||
puts 'graph_info This graph shows the ADSL line attenuation.'
|
||||
puts 'graph_title ADSL line attenuation'
|
||||
puts 'graph_vlabel attenuation dB'
|
||||
when 'margin', 'noise'
|
||||
puts 'graph_info This graph shows the ADSL SNR margin.'
|
||||
puts 'graph_title ADSL line SNR margin'
|
||||
puts 'graph_vlabel noise margin dB'
|
||||
end
|
||||
puts 'down.label downstream'
|
||||
puts 'up.label upstream'
|
||||
exit 0
|
||||
end
|
||||
|
||||
# Connect to the webadmin
|
||||
http = Net::HTTP.start(host,port)
|
||||
http = Net::HTTP.start(host, port)
|
||||
req = Net::HTTP::Get.new('/ADSLCStatus.htm')
|
||||
# send the login info
|
||||
req.basic_auth user, pass
|
||||
response = http.request(req)
|
||||
s = response.body
|
||||
|
||||
#Make sure we got the page successfully
|
||||
# Make sure we got the page successfully
|
||||
if response.code != '200'
|
||||
puts "Getting web page failed:"
|
||||
case response.code
|
||||
when '401'
|
||||
puts 'Probably because the username and password are incorrect'
|
||||
#Looks like the modem response with 200 when you try to access a page that does not exist >_>
|
||||
#when '404'
|
||||
# puts 'Looks like the page this plugin needs isn\'t available...'
|
||||
# puts 'Check your modem make/model/version'
|
||||
end
|
||||
puts s
|
||||
exit 1
|
||||
puts "Getting web page failed:"
|
||||
case response.code
|
||||
when '401'
|
||||
puts 'Probably because the username and password are incorrect'
|
||||
# Looks like the modem response with 200 when you try to access a page that does not exist >_>
|
||||
# when '404'
|
||||
# puts 'Looks like the page this plugin needs isn\'t available...'
|
||||
# puts 'Check your modem make/model/version'
|
||||
end
|
||||
puts s
|
||||
exit 1
|
||||
end
|
||||
|
||||
# Apply voodoo regex to the result HTML to get the data we want.
|
||||
case stat
|
||||
when 'syncrate'
|
||||
a = s.scan(/.*share\.curstate.*\n.*share\.downstr[^0-9]*([0-9]+).*share\.upstr[^0-9]*([0-9]+).*$/)
|
||||
b,c = a[0]
|
||||
puts 'down.value '+ (b.to_i*1000).to_s + "\n" + 'up.value '+ (c.to_i*1000).to_s
|
||||
exit 0
|
||||
when 'attenuation'
|
||||
a = s.scan(/.*share\.lineatt.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/)
|
||||
b,c = a[0]
|
||||
puts 'down.value '+ (b.to_i).to_s + "\n" + 'up.value '+ (c.to_i).to_s
|
||||
exit 0
|
||||
when 'margin','noise'
|
||||
a = s.scan(/.*share\.noise.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/)
|
||||
b,c = a[0]
|
||||
puts 'down.value '+ (b.to_i).to_s + "\n" + 'up.value '+ (c.to_i).to_s
|
||||
exit 0
|
||||
else
|
||||
puts 'Statistic ' + stat.to_s + ' not known, would you like me to fabricate it for you?'
|
||||
exit 1
|
||||
when 'syncrate'
|
||||
a = s.scan(/.*share\.curstate.*\n.*share\.downstr[^0-9]*([0-9]+).*share\.upstr[^0-9]*([0-9]+).*$/)
|
||||
b, c = a[0]
|
||||
puts 'down.value ' + (b.to_i * 1000).to_s + "\n" + 'up.value ' + (c.to_i * 1000).to_s
|
||||
exit 0
|
||||
when 'attenuation'
|
||||
a = s.scan(/.*share\.lineatt.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/)
|
||||
b, c = a[0]
|
||||
puts 'down.value ' + (b.to_i).to_s + "\n" + 'up.value ' + (c.to_i).to_s
|
||||
exit 0
|
||||
when 'margin', 'noise'
|
||||
a = s.scan(/.*share\.noise.*\n.*share\.down[^0-9]*([0-9]+).*share\.up[^0-9]*([0-9]+).*$/)
|
||||
b, c = a[0]
|
||||
puts 'down.value ' + (b.to_i).to_s + "\n" + 'up.value ' + (c.to_i).to_s
|
||||
exit 0
|
||||
else
|
||||
puts 'Statistic ' + stat.to_s + ' not known, would you like me to fabricate it for you?'
|
||||
exit 1
|
||||
end
|
||||
|
|
|
@ -31,7 +31,6 @@ require 'mechanize'
|
|||
require 'digest/md5'
|
||||
require 'nokogiri'
|
||||
|
||||
|
||||
def output
|
||||
nics = Hash.new
|
||||
nics["LAN"] = Hash.new
|
||||
|
@ -80,7 +79,7 @@ def output
|
|||
j = 0
|
||||
doc = Nokogiri::XML(clients_xml.to_s)
|
||||
doc.xpath('//assoc').each do |assoc|
|
||||
j+=1
|
||||
j += 1
|
||||
end
|
||||
puts "wifi_assoc.value " + j.to_s
|
||||
|
||||
|
@ -89,7 +88,7 @@ def output
|
|||
j = 0
|
||||
doc = Nokogiri::XML(clients_xml.to_s)
|
||||
doc.xpath('//client').each do |client|
|
||||
j+=1
|
||||
j += 1
|
||||
end
|
||||
puts "dhcp_clients.value " + j.to_s
|
||||
|
||||
|
@ -98,31 +97,31 @@ def output
|
|||
clients_xml = agent.get("#{router_path}/wan_connection_status.xml").body
|
||||
doc = Nokogiri::XML(clients_xml.to_s)
|
||||
uptime = doc.children.search('wan_interface_up_time_0')[0].text
|
||||
puts "uptime.value " + sprintf( "%.2f", (Float(uptime)/86400) )
|
||||
puts "uptime.value " + sprintf("%.2f", (Float(uptime) / 86400))
|
||||
|
||||
# graph overall interface packets transferred per interval
|
||||
puts "multigraph if_packets"
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "#{i}_recv.value " + nics[i]["packets_received"]
|
||||
puts "#{i}_send.value " + nics[i]["packets_sent"]
|
||||
end
|
||||
|
||||
# graph overall interface dropped packets per interval
|
||||
puts "multigraph if_drop"
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "#{i}_recv.value " + nics[i]["rx_dropped"]
|
||||
puts "#{i}_send.value " + nics[i]["tx_dropped"]
|
||||
end
|
||||
|
||||
# graph overall interface collisions & errors per interval
|
||||
puts "multigraph if_collerr"
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "#{i}_coll.value " + nics[i]["tx_collisions"]
|
||||
puts "#{i}_err.value " + nics[i]["rx_errors"]
|
||||
end
|
||||
|
||||
# graph stats for each interface
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "multigraph if_packets.#{i}"
|
||||
puts "send.value " + nics[i]["packets_sent"]
|
||||
puts "recv.value " + nics[i]["packets_received"]
|
||||
|
@ -135,7 +134,6 @@ def output
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def config
|
||||
# build the configuration for graphs
|
||||
puts "multigraph if_packets"
|
||||
|
@ -143,7 +141,7 @@ def config
|
|||
puts 'graph_category network'
|
||||
puts 'graph_order LAN_recv LAN_send WAN_recv WAN_send WLAN_recv WLAN_send'
|
||||
puts 'graph_vlabel packets in (-) / out (+) per ${graph_period}'
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "#{i}_recv.type DERIVE"
|
||||
puts "#{i}_recv.graph no"
|
||||
puts "#{i}_recv.min 0"
|
||||
|
@ -158,7 +156,7 @@ def config
|
|||
puts 'graph_category network'
|
||||
puts 'graph_order LAN_recv LAN_send WAN_recv WAN_send WLAN_recv WLAN_send'
|
||||
puts 'graph_vlabel packets / ${graph_period}'
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "#{i}_recv.type DERIVE"
|
||||
puts "#{i}_recv.graph no"
|
||||
puts "#{i}_recv.min 0"
|
||||
|
@ -173,7 +171,7 @@ def config
|
|||
puts 'graph_category network'
|
||||
puts 'graph_order LAN_coll LAN_err WAN_coll WAN_err WLAN_coll WLAN_coll'
|
||||
puts 'graph_vlabel packets / ${graph_period}'
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "#{i}_coll.label #{i} collisions"
|
||||
puts "#{i}_coll.type DERIVE"
|
||||
puts "#{i}_coll.min 0"
|
||||
|
@ -201,7 +199,7 @@ def config
|
|||
puts 'uptime.label uptime'
|
||||
puts 'uptime.draw AREA'
|
||||
|
||||
for i in [ "LAN", "WAN", "WLAN" ] do
|
||||
for i in ["LAN", "WAN", "WLAN"] do
|
||||
puts "multigraph if_packets.#{i}"
|
||||
puts "graph_title D-Link DIR-655 #{i} traffic"
|
||||
puts 'graph_category network'
|
||||
|
@ -244,7 +242,6 @@ def config
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
# main
|
||||
if ARGV.length == 1 and ARGV[0] == 'config'
|
||||
config()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue