jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [traffic/] [platform/] [syssnmp.pm] - Diff between revs 1 and 18

Show entire file Ignore whitespace

Rev 1 Rev 18
Line 10... Line 10...
   
sub do_snmp { sub do_snmp {
my $oid = '.1.3.6.1.2.1.2.2.1'; my $oid = '.1.3.6.1.2.1.2.2.1';
# interfaces.ifTable.ifEntry.ifDesc # interfaces.ifTable.ifEntry.ifDesc
   
my $suf_descr = '.2'; my $suf_descr = '.1';
# .ifDescr # .ifDescr
my $suf_in = '.10'; my $suf_in = '.10';
# .ifInOctets # .ifInOctets
my $suf_out = '.16'; my $suf_out = '.16';
# .ifOutOctets # .ifOutOctets
   
my (%targets) = @_; my (%targets) = @_;
  my (%snmpdev) = @_;
   
foreach ( keys(%targets) ) { foreach ( keys(%targets) ) {
# print "1 $_\n";  
my ($host, $com) = split /_/; my ($host, $com) = split /_/;
my ($res, $lastnic, @nics); my ($res, $lastnic, %nics);
   
my $i = 0; my $i = 0;
my $switch = 0; #pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics
my $portnum = "none";  
for (@{$targets{$_}}) { for (@{$targets{$_}}) {
my (undef, $portnum) = split /port/;  
   
if ("port$portnum" eq $_) {  
# print "Je to switch\n";  
$switch = 1;  
$port = $portnum;  
if($i == 0) {  
$nics{$_} = 0;  
$lastnic = $port;  
$i++;  
} else {  
$nics{$lastnic} = $_;  
$i = 0;  
}  
} else {  
if($i == 0) { if($i == 0) {
$nics{$_} = 0; $nics{$_} = 0;
$lastnic = $_; $lastnic = $_;
$i++; $i++;
} else { } else {
$nics{$lastnic} = $_; $nics{$lastnic} = $_;
$i = 0; $i = 0;
} }
}  
} }
# print "2 $_ a $port\n";  
# print "3 $host a $com b $lastnic c $nics{$dev}\n";  
   
my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out); my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out);
# print "4 @query\n";  
$res = HotSaNICsnmp::snmp_walk($host, $com, @query); $res = HotSaNICsnmp::snmp_walk($host, $com, @query);
# print "5 $res\n";  
   
#pokud nejsou vysledky tak se zapise do databaze Undef stav  
if(keys(%$res) == 0) { if(keys(%$res) == 0) {
# print "tady to je kdyz nejni spojeni tak se do rrd da undef";  
if ($switch == 1) { do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics);
do_rrd($host."_port".$_, "U", "U", $nics{$_}) foreach keys(%nics);  
} else {  
do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics);  
}  
return undef; return undef;
} }
  my $koncovy = 200;
$necodef = defined($$res{$oid.$suf_descr.".".$i}); for ( my $i=1; $i < $koncovy; $i++) {
# print "5a $necodef\n"; my $dev = $$res{$oid.$suf_descr.".".$i};
#jedem na prohledani vsech ifaces a pokud souhlasi tak se pise do rrd my $devin = $$res{$oid.$suf_in.".".$i};
for ( my $i=1; defined($$res{$oid.$suf_descr.".".$i}); $i++) { my $devout = $$res{$oid.$suf_out.".".$i};
if ($switch == 1) { if(defined($nics{$dev})) {
#toto je cast pro switch a jde se na rrd pokud souhlasi poradi portu  
#jmeno iface se neda pro rozpoznani pouzit protoze je pro vsechny stejne  
my $dev = $$res{$oid.$suf_descr.".".$i};  
# print "5b $dev\n";  
if(defined($nics{$i})) {  
# print "5b $nics{$i}\n";  
do_rrd($host."_port".$i, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$i});  
}  
} else {  
#zde rozpoznavame podle jmena iface  
my $dev = $$res{$oid.$suf_descr.".".$i};  
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});
} }
}  
} }
} }
   
} }
   
sub do_rrd { sub do_rrd {
my ($name, $in, $out, $max) = @_; my ($name, $in, $out, $max) = @_;
#print "mam tu $max";  
if (! -e "rrd/$name.rrd" ) { if (! -e "rrd/$name.rrd" ) {
system("./makerrd","$name","$max") system("./makerrd","$name","$max")
} }
   
RRDs::update "rrd/$name.rrd",time.":".$in.":".$out; RRDs::update "rrd/$name.rrd",time.":".$in.":".$out;

Powered by WebSVN 2.2.1