#!/usr/bin/perl # -*- cperl -*- =head1 NAME TG585v7_ - Munin plugin to monitor the stats of a Thomson TG585 v7. =head1 APPLICABLE SYSTEMS Any system with access to a Thomson TG585 v7 ADSL router. Requires perl and WWW::Mechanize. =head1 CONFIGURATION The plugin needs HTML access to the router. If you can get to http://YOUR_ROUTER/, and are greeting with a page titled "THOMSON TG585 v7", then you can probably use this plugin. This is a wildcard plugin, so you will need to create symlinks to this plugin (or create copies if your filesystem doesn't support linking). Links should be of the form: TG585v7__ where "" is one of "bandwidth", "power", "errors" or "uptime" (thus you probably want 4 symlinks in total. =head1 MAGIC MARKERS #%# family=auto #%# capabilities=autoconf =head1 BUGS Please report bugs to L. =head1 AUTHOR Unknown =head1 LICENSE GPL =cut use strict; use warnings; use lib $ENV{'MUNIN_LIBDIR'}; use Munin::Plugin; my $ret; if ( !eval "require WWW::Mechanize;" ) { $ret = "Could not load WWW::Mechanize"; } my $USER = $ENV{user}; my $PASS = $ENV{pass}; our @name_fields = split /_/, $0; if (scalar @name_fields == 3){ if ($name_fields[1] eq '' or $name_fields[2] eq ''){ print "Misconfigured symlink. See Documentation\n"; exit 1; } } else { print "Misconfigured symlink. See Documentation\n"; exit 1; } my $host = $name_fields[1]; my $mode = $name_fields[2]; if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) { if ($ret) { print "no ($ret)\n"; exit 1; } print "yes\n"; exit 0; } if ( defined $ARGV[0] and $ARGV[0] eq "config" ) { if ($ret) { print $ret; exit 1; } print "host_name $host\n" unless $host eq 'localhost'; if ($mode eq 'bandwidth'){ print <new(); $mech->credentials($USER, $PASS); if ($mode eq 'bandwidth' or $mode eq 'power' or $mode eq 'errors'){ $mech->get("http://$host/cgi/b/dsl/dt/?be=0&l0=1&l1=0"); } elsif ($mode eq 'uptime'){ $mech->get("http://$host/cgi/b/bb/?be=0&l0=2&l1=-1"); } if ($mech->success()){ my $page = $mech->content; if ($mode eq 'bandwidth'){ $page =~ m{Bandwidth \(Up/Down\).*]+>([\d,\.]+) / ([\d,\.]+)}; my $upBW = $1; my $downBW = $2; $upBW =~ s/,//; $downBW =~ s/,//; print "down.value $downBW\n"; print "up.value $upBW\n"; } elsif ($mode eq 'power'){ $page =~ m{Output Power.*]+>([\d,\.]+) / ([\d,\.]+)}; my $upOUT = $1; my $downOUT = $2; $upOUT =~ s/,//; $downOUT =~ s/,//; $page =~ m{Line Attenuation.*]+>([\d,\.]+) / ([\d,\.]+)}; my $upLINE = $1; my $downLINE = $2; $upLINE =~ s/,//; $downLINE =~ s/,//; $page =~ m{SN Margin.*]+>([\d,\.]+) / ([\d,\.]+)}; my $upSN = $1; my $downSN = $2; $upSN =~ s/,//; $downSN =~ s/,//; print "downout.value $downOUT\n"; print "upout.value $upOUT\n"; print "downline.value $downLINE\n"; print "upline.value $upLINE\n"; print "downsn.value $downSN\n"; print "upsn.value $upSN\n"; } elsif ($mode eq 'errors'){ $page =~ m{FEC Errors.*]+>([\d,\.]+) / ([\d,\.]+)}; my $upFEC = $1; my $downFEC = $2; $upFEC =~ s/,//g; $downFEC =~ s/,//g; $page =~ m{CRC Errors.*]+>([\d,\.]+) / ([\d,\.]+)}; my $upCRC = $1; my $downCRC = $2; $upCRC =~ s/,//g; $downCRC =~ s/,//g; $page =~ m{HEC Errors.*]+>([\d,\.]+) / ([\d,\.]+)}; my $upHEC = $1; my $downHEC = $2; $upHEC =~ s/,//g; $downHEC =~ s/,//g; print "downFEC.value $downFEC\n"; print "upFEC.value $upFEC\n"; print "downCRC.value $downCRC\n"; print "upCRC.value $upCRC\n"; print "downHEC.value $downHEC\n"; print "upHEC.value $upHEC\n"; } elsif ($mode eq 'uptime'){ my ($DSLRaw, $DSLUp, $iNetRaw, $iNetUp, $BoxRaw, $BoxUp); if ($page =~ m{Uptime:.*]+>(.*)}g){ $DSLRaw = $1; $DSLUp = Uptime2Days($DSLRaw); } else { $DSLUp = 'U'; } if ($page =~ m{Uptime:.*]+>(.*)}g){ $iNetRaw = $1; $iNetUp = Uptime2Days($iNetRaw); } else { $iNetUp = 'U'; } $mech->get("http://$host/cgi/b/cfg/ov/?be=0&l0=1&l1=1"); $page = $mech->content; if ($page =~ m{Time Since Power-on:.*]+>(.*)}){ $BoxRaw = $1; $BoxUp = Uptime2Days($BoxRaw); } else { $BoxUp = 'U'; } print "Box.value $BoxUp\n"; print "Box.extinfo $BoxRaw\n"; print "DSL.value $DSLUp\n"; print "DSL.extinfo $DSLRaw\n"; print "iNet.value $iNetUp\n"; print "iNet.extinfo $iNetRaw\n"; } else { print "Don't know how to graph $mode\n"; exit 1; } exit 0; }