hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
package syssnmp;
use lib "../../../lib";
use HotSaNICsnmp;
sub version {
($VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/;
return "syssnmp.pm $VERSION";
}
sub do_snmp {
#my $oid = '.1.3.6.1.2.1.2.2.1';
my $oid = '.1.3.6.1.2.1.31.1.1.1';
# interfaces.ifTable.ifEntry.ifDesc
my $suf_descr = '.1';
# .ifDescr
my $suf_in = '.6';
# .ifInOctets
my $suf_out = '.10';
# .ifOutOctets
my (%targets) = @_;
my (%snmpdev) = @_;
foreach ( keys(%targets) ) {
my ($host, $com) = split /_/;
my ($res, $lastnic, %nics);
my $i = 0;
#pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics
for (@{$targets{$_}}) {
if($i == 0) {
$nics{$_} = 0;
$lastnic = $_;
$i++;
} else {
$nics{$lastnic} = $_;
$i = 0;
}
}
my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out);
$res = HotSaNICsnmp::snmp_walk($host, $com, @query);
if(keys(%$res) == 0) {
print "vytvarim pro $_ ... $nics{$_}";
do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics);
return undef;
}
#ciselne porty
my $koncovy = 600;
for ( my $i=1; $i < $koncovy; $i++) {
my $dev = $$res{$oid.$suf_descr.".".$i};
my $devin = $$res{$oid.$suf_in.".".$i};
my $devout = $$res{$oid.$suf_out.".".$i};
if(defined($nics{$dev})) {
do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev});
}
}
#jmenne porty
for ( my $i=1; defined($$res{$oid.$suf_descr.".".$i}); $i++) {
my $dev = $$res{$oid.$suf_descr.".".$i};
print "1 mam tu $dev";
if(defined($nics{$dev})) {
do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev});
}
}
}
}
sub do_rrd {
my ($name, $in, $out, $max) = @_;
$name =~ s/\//-/g;
if (! -e "rrd/$name.rrd" ) {
system("./makerrd","$name","$max")
}
RRDs::update "rrd/$name.rrd",time.":".$in.":".$out;
if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
}
1;