#!/usr/bin/perl -w # # Warning: due to limitations in the Netgear DG834G, this # script only shows packets sent and received, NOT data in # bytes, as MRTG expects. # # Warning: this script requires at least firmware V1.05.00 # on the Netgear DG834G. # # Copyright 2004 Ketil Froyn # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Synopsis: # Add something like this to your mrtg.cfg file: # # Target[adsl]: `/usr/local/bin/dg834g-mrtg.pl admin password ip` # # Then mrtg should collect numbers of packages transferred over the PPoA # link. # # BUGS: # The Netgear DG834G only shows packets transferred, not amount # of data. So we're ONLY COUNTING PACKETS, NOT BYTES. # # (C) Ketil Froyn, 2004 use strict; my $admin = shift || die "Required first argument: Admin username for DG834G"; my $pass = shift || die "Required second argument: Admin password for DG834G"; my $ip = shift || die "Required third argument: IP address of DG834G"; my $cmd = qq{wget -q -O - "--http-user=$admin" "--http-passwd=$pass" "http://$ip/setup.cgi?next_file=stattbl.htm"}; open F, "$cmd |" or die "Unable to run wget: $!"; my $s = join "", ; close F; if ($s =~ /class="thead">WAN<.+?class="ttext">PPPoA<.+?class="ttext">(\d+)<.+?class="ttext">(\d+)<.+?class="ttext">([\d:]+)<\/span><\/td>\s*<\/tr>/si) { print "$2\n$1\n$3\nNetgear DG834G\n"; } else { print STDERR "No data found\n"; exit(1); }