/usr/share/doc/libsnmp-multi-perl/examples/traffic.pl is in libsnmp-multi-perl 2.1-4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #!/usr/bin/perl -w
#
# $Id: traffic.pl,v 1.1.1.1 2003/12/18 01:16:52 toni Exp $
#
# A simple application to query the in/out octet counts on all interfaces
# on a set of routers, and sum up the total bytes of traffic carried.
#
# Note that this example does not really work as it doesn't take into
# account wrapped counters or skew across responses. But the basic idea
# is sound.
#
use strict;
use Carp;
use SNMP::Multi;
my $read_comm = 'Super!Secret';
my @all_routers = qw/ router01.my.com router02.my.com router03.my.com
router04.my.com router05.my.com /;
my $sm = SNMP::Multi->new(
Method => 'bulkwalk',
Community => $read_comm,
Requests => SNMP::Multi::VarReq->new(
hosts => [ @all_routers ],
vars => [ [ 'ifOutOctets' ], [ 'ifInOctets' ] ],
),
) or croak "$SNMP::Multi::error\n";
my $resp = $sm->execute() or croak $sm->error();
my $sum = 0;
grep { $sum += ($_ ? $_ : 0) } $resp->values();
print "Total traffic: $sum bytes.\n";
exit 0;
|