hotsanic |
Subversion Repositories: |
Rev 22 | Rev 23 | |
---|---|---|
Line 7... | Line 7... | |
($VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/; |
($VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/; | |
return "syssnmp.pm $VERSION"; |
return "syssnmp.pm $VERSION"; | |
} |
} | |
|
| |
sub do_snmp { |
sub do_snmp { | |
#my $oid = '.1.3.6.1.2.1.2.2.1'; |
#counter64 oid | |
my $oid = '.1.3.6.1.2.1.31.1.1.1'; |
my $oid = '.1.3.6.1.2.1.31.1.1.1'; | |
# interfaces.ifTable.ifEntry.ifDesc |
||
|
||
my $suf_descr = '.1'; |
my $suf_descr = '.1'; | |
# .ifDescr |
||
my $suf_in = '.6'; |
my $suf_in = '.6'; | |
# .ifInOctets |
||
my $suf_out = '.10'; |
my $suf_out = '.10'; | |
# .ifOutOctets |
||
|
||
my (%targets) = @_; |
my (%targets) = @_; | |
my (%snmpdev) = @_; |
||
|
| |
foreach ( keys(%targets) ) { |
foreach ( keys(%targets) ) { | |
my ($host, $com) = split /_/; |
my ($host, $com) = split /_/; | |
my ($res, $lastnic, %nics); |
my ($res, $lastnic, %nics); | |
my $i = 0; |
my $i = 0; | |
Line 35... | Line 28... | |
$i++; |
$i++; | |
} else { |
} else { | |
$nics{$lastnic} = $_; |
$nics{$lastnic} = $_; | |
$i = 0; |
$i = 0; | |
} |
} | |
} |
} # for targets | |
|
| |
my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out); |
my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out); | |
$res = HotSaNICsnmp::snmp_walk($host, $com, @query); |
$res = HotSaNICsnmp::snmp_walk($host, $com, @query); | |
| ||
#pokud nic nedostaneme tak se dosadi undef | ||
if(keys(%$res) == 0) { |
if(keys(%$res) == 0) { | |
print "vytvarim pro $_ ... $nics{$_}"; |
||
do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics); |
do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics); | |
return undef; |
return undef; | |
} |
} # if | |
#ciselne porty |
| |
my $koncovy = 600; |
#projdeme vysledek a zapiseme do databaze | |
for ( my $i=1; $i < $koncovy; $i++) { |
foreach ( keys(%$res) ) { | |
my $dev = $$res{$oid.$suf_descr.".".$i}; |
my @oidnums = split(/\./, $_); | |
my $devin = $$res{$oid.$suf_in.".".$i}; |
#pokud je to descr tak vyzvedneme jmeno dev a jdem na zapis | |
my $devout = $$res{$oid.$suf_out.".".$i}; |
if($oidnums[11]==1) { | |
if(defined($nics{$dev})) { |
my $dev = $$res{$_}; | |
do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev}); |
my $i = $oidnums[12]; | |
} |
#pokud dev existuje jdemem na zapis | |
} |
||
#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})) { |
if(defined($nics{$dev})) { | |
do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev}); |
do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev}); | |
} |
} # if defined | |
} |
} # if oidnums | |
} |
} # foreach res | |
|
} # foreach targets | |
} |
} # do_snmp | |
|
| |
sub do_rrd { |
sub do_rrd { | |
my ($name, $in, $out, $max) = @_; |
my ($name, $in, $out, $max) = @_; | |
$name =~ s/\//-/g; |
$name =~ s/\//-/g; | |
if (! -e "rrd/$name.rrd" ) { |
if (! -e "rrd/$name.rrd" ) { |