root / plugins / network / http__tp_link @ 92483a04
Historique | Voir | Annoter | Télécharger (1,87 ko)
| 1 |
#!/usr/bin/env ruby |
|---|---|
| 2 |
|
| 3 |
if $0 =~ /^(?:|.*\/)http_([^_]+)_/ |
| 4 |
host = $1 |
| 5 |
end |
| 6 |
abort "# Error: couldn't understand what I'm supposed to monitor." unless host |
| 7 |
|
| 8 |
user = ENV['user'] || 'user' |
| 9 |
password = ENV['password'] || 'user' |
| 10 |
|
| 11 |
if (ARGV[0] == 'config') |
| 12 |
puts "host_name #{host}" unless host == 'localhost'
|
| 13 |
|
| 14 |
puts "multigraph dsl_rate" |
| 15 |
puts "graph_title DSL line speed" |
| 16 |
puts "graph_args --base 1000 -l 0" |
| 17 |
puts "graph_vlabel bps" |
| 18 |
puts "graph_category network" |
| 19 |
puts "downstream.label downstream" |
| 20 |
puts "downstream.type GAUGE" |
| 21 |
puts "downstream.min 0" |
| 22 |
puts "downstream.cdef downstream,1000,*" |
| 23 |
puts "upstream.label upstream" |
| 24 |
puts "upstream.type GAUGE" |
| 25 |
puts "upstream.min 0" |
| 26 |
puts "upstream.cdef upstream,1000,*" |
| 27 |
|
| 28 |
puts "multigraph dsl_snr" |
| 29 |
puts "graph_title DSL SNR" |
| 30 |
puts "graph_args --base 1000 -l 0" |
| 31 |
puts "graph_vlabel dB" |
| 32 |
puts "graph_scale no" |
| 33 |
puts "graph_category network" |
| 34 |
puts "downstream.label downstream" |
| 35 |
puts "downstream.type GAUGE" |
| 36 |
puts "downstream.min 0" |
| 37 |
puts "upstream.label upstream" |
| 38 |
puts "upstream.type GAUGE" |
| 39 |
puts "upstream.min 0" |
| 40 |
|
| 41 |
exit 0 |
| 42 |
end |
| 43 |
|
| 44 |
require 'net/http' |
| 45 |
|
| 46 |
class TPAdslStats |
| 47 |
def initialize(host, user, password) |
| 48 |
Net::HTTP.start( host ) do |http| |
| 49 |
req = Net::HTTP::Get.new('/statsadsl.html')
|
| 50 |
req.basic_auth user, password |
| 51 |
response = http.request(req) |
| 52 |
abort "# Error: #{response.code} received fetching stats" unless response.is_a?(Net::HTTPSuccess)
|
| 53 |
@html = response.body |
| 54 |
end |
| 55 |
end |
| 56 |
|
| 57 |
def field_values(label) |
| 58 |
if @html =~ />#{label}.*?<td>([0-9.]+).*?([0-9.]+)/m
|
| 59 |
[$1, $2] |
| 60 |
else |
| 61 |
['U', 'U'] |
| 62 |
end |
| 63 |
end |
| 64 |
end |
| 65 |
|
| 66 |
stats = TPAdslStats.new(host, user, password) |
| 67 |
|
| 68 |
puts "multigraph dsl_rate" |
| 69 |
rate = stats.field_values('Rate')
|
| 70 |
puts "downstream.value #{rate[0]}"
|
| 71 |
puts "upstream.value #{rate[1]}"
|
| 72 |
|
| 73 |
puts "multigraph dsl_snr" |
| 74 |
snr = stats.field_values('SNR')
|
| 75 |
puts "downstream.value #{snr[0]}"
|
| 76 |
puts "upstream.value #{snr[1]}"
|
