diff options
Diffstat (limited to 'collectors')
-rwxr-xr-x | collectors/ping.pl | 28 | ||||
-rwxr-xr-x | collectors/snmpfetchng.pl | 27 |
2 files changed, 40 insertions, 15 deletions
diff --git a/collectors/ping.pl b/collectors/ping.pl index 590379c..d5acded 100755 --- a/collectors/ping.pl +++ b/collectors/ping.pl @@ -1,7 +1,7 @@ #! /usr/bin/perl use DBI; use POSIX; -use Time::HiRes; +use Time::HiRes qw(sleep time); use Net::Oping; use strict; use warnings; @@ -15,13 +15,21 @@ my $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null ORDER BY random()"); -my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null"); +my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null or mgmt_v6_addr is not null ORDER BY random();"); +my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null;"); +my $last = time(); +my $target = 0.2; while (1) { + my $now = time(); + my $elapsed = ($now - $last); + if ($elapsed < $target) { + sleep($target - ($now - $last)); + } + $last = time(); # ping loopbacks my $ping = Net::Oping->new; - $ping->timeout(0.3); + $ping->timeout(0.2); $q->execute; my %ip_to_switch = (); @@ -32,8 +40,10 @@ while (1) { my $switch = $ref->{'switch'}; my $ip = $ref->{'ip'}; - $ping->host_add($ip); - $ip_to_switch{$ip} = $switch; + if (defined($ip) ) { + $ping->host_add($ip); + $ip_to_switch{$ip} = $switch; + } my $secondary_ip = $ref->{'secondary_ip'}; if (defined($secondary_ip)) { @@ -55,7 +65,9 @@ while (1) { my $drops = 0; while (my ($ip, $latency) = each %$result) { my $switch = $ip_to_switch{$ip}; - next if (!defined($switch)); + if (!defined($switch)) { + next; + } if (!defined($latency)) { $drops += $dropped{$ip}; @@ -81,7 +93,7 @@ while (1) { $dbh->commit; # ping linknets $ping = Net::Oping->new; - $ping->timeout(0.3); + $ping->timeout(0.2); $lq->execute; my @linknets = (); 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(); |