aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@frank.tg14.gathering.org>2014-04-15 17:21:33 +0200
committerroot <root@frank.tg14.gathering.org>2014-04-15 17:21:33 +0200
commit5ab53b8b11a3a904c204e722c758735db4e1555d (patch)
tree59132ab7e6ec7b845049171800ce684aae7d664c
parentdcd2aeaa340a2d73e600271aaa7760afef943e79 (diff)
Make ping.pl ping linknets.
-rwxr-xr-xclients/ping.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/clients/ping.pl b/clients/ping.pl
index c33c8cf..6968b4d 100755
--- a/clients/ping.pl
+++ b/clients/ping.pl
@@ -14,8 +14,10 @@ $dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
my $q = $dbh->prepare("SELECT switch,ip FROM switches WHERE ip<>'127.0.0.1'");
+my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets");
while (1) {
+ # ping loopbacks
my $ping = Net::Oping->new;
$ping->timeout(0.2);
@@ -41,6 +43,30 @@ while (1) {
}
$dbh->pg_putcopyend();
$dbh->commit;
+
+ # ping linknets
+ $ping = Net::Oping->new;
+ $ping->timeout(0.2);
+
+ $lq->execute;
+ my @linknets = ();
+ while (my $ref = $lq->fetchrow_hashref) {
+ push @linknets, $ref;
+ $ping->host_add($ref->{'addr1'});
+ $ping->host_add($ref->{'addr2'});
+ }
+ $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->pg_putcopyend();
+ $dbh->commit;
sleep 1;
}