diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-03-16 18:15:52 +0000 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-03-16 18:15:52 +0000 |
commit | 4666a02a51fa313e34875c169502a0cecf834b1c (patch) | |
tree | 1304ed9ed0c978465b2ffaae2ba19b455d32761c /clients/ping.pl | |
parent | 783096cef942a275f23f7c7cb63bbca175cff0ba (diff) |
NMS: Rewrite the SNMP fetcher and whatnot
Again.
It's using the prototype, and the objects are configurable. I assume this
will need some work.
Also: I touched ping up to make it work without linknets.
Diffstat (limited to 'clients/ping.pl')
-rwxr-xr-x | clients/ping.pl | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/clients/ping.pl b/clients/ping.pl index 8d216ef..80c389a 100755 --- a/clients/ping.pl +++ b/clients/ping.pl @@ -13,7 +13,7 @@ my $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $q = $dbh->prepare("SELECT switch,ip,secondary_ip FROM switches WHERE ip<>'127.0.0.1'"); +my $q = $dbh->prepare("SELECT switch,ip,secondary_ip FROM switches WHERE ip is not null"); my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets"); while (1) { @@ -36,7 +36,6 @@ while (1) { $ping->host_add($secondary_ip); $secondary_ip_to_switch{$secondary_ip} = $switch; } - print "ip: $ip\n"; } my $result = $ping->ping(); die $ping->get_error if (!defined($result)); @@ -73,18 +72,19 @@ while (1) { $ping->host_add($ref->{'addr1'}); $ping->host_add($ref->{'addr2'}); } - $result = $ping->ping(); - die $ping->get_error if (!defined($result)); + if (@linknets) { + $result = $ping->ping(); + die $ping->get_error if (!defined($result)); - $dbh->do('COPY linknet_ping (linknet, latency1_ms, latency2_ms) FROM STDIN'); # date is implicitly now. - for my $linknet (@linknets) { - my $id = $linknet->{'linknet'}; - my $latency1 = $result->{$linknet->{'addr1'}} // '\N'; - my $latency2 = $result->{$linknet->{'addr2'}} // '\N'; - $dbh->pg_putcopydata("$id\t$latency1\t$latency2\n"); + $dbh->do('COPY linknet_ping (linknet, latency1_ms, latency2_ms) FROM STDIN'); # date is implicitly now. + for my $linknet (@linknets) { + my $id = $linknet->{'linknet'}; + my $latency1 = $result->{$linknet->{'addr1'}} // '\N'; + my $latency2 = $result->{$linknet->{'addr2'}} // '\N'; + $dbh->pg_putcopydata("$id\t$latency1\t$latency2\n"); + } + $dbh->pg_putcopyend(); } - $dbh->pg_putcopyend(); $dbh->commit; - } |