diff options
Diffstat (limited to 'collectors/snmpfetchng.pl')
-rwxr-xr-x | collectors/snmpfetchng.pl | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/collectors/snmpfetchng.pl b/collectors/snmpfetchng.pl index 5c4b053..566e48c 100755 --- a/collectors/snmpfetchng.pl +++ b/collectors/snmpfetchng.pl @@ -7,7 +7,7 @@ use POSIX; use SNMP; use Data::Dumper; use lib '/opt/gondul/include'; -use nms; +use nms qw(convert_mac); SNMP::initMib(); SNMP::addMibDirs("/opt/gondul/mibs/StandardMibs"); @@ -22,13 +22,13 @@ $dbh->{RaiseError} = 1; my $qualification = <<"EOF"; (last_updated IS NULL OR now() - last_updated > poll_frequency) AND (locked='f' OR now() - last_updated > '15 minutes'::interval) -AND mgmt_v4_addr is not null +AND (mgmt_v4_addr is not null or mgmt_v6_addr is not null) EOF # Borrowed from snmpfetch.pl our $qswitch = $dbh->prepare(<<"EOF") SELECT - sysname,switch,host(mgmt_v4_addr) as ip,community, + sysname,switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as ip2,community, DATE_TRUNC('second', now() - last_updated - poll_frequency) AS overdue FROM switches @@ -63,10 +63,15 @@ sub populate_switches or die "Couldn't get switch"; $dbh->commit; while (my $ref = $qswitch->fetchrow_hashref()) { + my $ip; + $ip = $ref->{'ip'}; + if (!defined($ip) or $ip eq "") { + $ip = 'udp6:[' . $ref->{'ip2'} . ']'; + } push @switches, { 'sysname' => $ref->{'sysname'}, 'id' => $ref->{'switch'}, - 'mgtip' => $ref->{'ip'}, + 'mgtip' => $ip, 'community' => $ref->{'community'} }; } @@ -104,13 +109,15 @@ sub callback{ my %ttop; my %nics; my @nicids; + my $total = 0; for my $ret (@top) { for my $var (@{$ret}) { for my $inner (@{$var}) { + $total++; my ($tag,$type,$name,$iid, $val) = ( $inner->tag ,$inner->type , $inner->name, $inner->iid, $inner->val); if ($tag eq "ifPhysAddress") { - next; + $val = convert_mac($val); } $tree{$iid}{$tag} = $val; if ($tag eq "ifIndex") { @@ -130,11 +137,17 @@ sub callback{ $tree2{'misc'}{$key}{$iid} = $tree{$iid}{$key}; } } - $sth->execute($switch{'sysname'}, JSON::XS::encode_json(\%tree2)); + if ($total > 0) { + $sth->execute($switch{'sysname'}, JSON::XS::encode_json(\%tree2)); + } $qunlock->execute($switch{'id'}) or die "Couldn't unlock switch"; $dbh->commit; - mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s."); + if ($total > 0) { + mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s."); + } else { + mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s - no data. Timeout?"); + } } while (1) { inner_loop(); |