1 |
dpavlin |
1 |
#!/usr/bin/perl -w |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
|
5 |
|
|
use constant RRD_CMD => '/home/rrd/bin/rrd-server.pl -u %s'; |
6 |
|
|
use constant SNMP_CMDS => ( |
7 |
|
|
'/usr/bin/snmpwalk -c public -v 2c %s IF-MIB::ifInOctets', |
8 |
|
|
'/usr/bin/snmpwalk -c public -v 2c %s IF-MIB::ifOutOctets' |
9 |
|
|
); |
10 |
|
|
use constant HOSTS => qw( |
11 |
|
|
switch1.company.com |
12 |
|
|
switch2.company.com |
13 |
|
|
switch3.company.com |
14 |
|
|
switch4.company.com |
15 |
|
|
); |
16 |
|
|
|
17 |
|
|
for my $host (HOSTS) { |
18 |
|
|
my %update; |
19 |
|
|
my $time = time; |
20 |
|
|
|
21 |
|
|
for my $cmd (SNMP_CMDS) { |
22 |
|
|
$cmd = sprintf($cmd,$host); |
23 |
|
|
print "$cmd\n"; |
24 |
|
|
for (qx($cmd)) { |
25 |
|
|
if (my ($key,$port,$value) = $_ =~ /(if(?:In|Out)Octets)\.(\d+)\s*=\s*(?:Counter32:\s*)?(\d+)/i) { |
26 |
|
|
$update{"$time.switch.traffic.$key"} += $value; |
27 |
|
|
$update{"$time.switch.traffic.port$port.$key"} = $value; |
28 |
|
|
} |
29 |
|
|
} |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
my $str; |
33 |
|
|
$str .= "$_ $update{$_}\n" for sort keys %update; |
34 |
|
|
my $cmd = sprintf(RRD_CMD,$host); |
35 |
|
|
print "$cmd\n"; |
36 |
|
|
open(PH,'|-',$cmd) || die "Unable to open file handle PH for command '$cmd': $!"; |
37 |
|
|
print PH $str; |
38 |
|
|
close(PH) || die "Unable to close file hadle PH for command '$cmd': $!"; |
39 |
|
|
} |
40 |
|
|
|