aboutsummaryrefslogtreecommitdiffstats
path: root/clients/ping.pl
diff options
context:
space:
mode:
Diffstat (limited to 'clients/ping.pl')
-rwxr-xr-xclients/ping.pl30
1 files changed, 24 insertions, 6 deletions
diff --git a/clients/ping.pl b/clients/ping.pl
index 6968b4d..b41febd 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 FROM switches WHERE ip<>'127.0.0.1'");
+my $q = $dbh->prepare("SELECT switch,ip,secondary_ip FROM switches WHERE ip<>'127.0.0.1'");
my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets");
while (1) {
@@ -23,11 +23,19 @@ while (1) {
$q->execute;
my %ip_to_switch = ();
+ my %secondary_ip_to_switch = ();
while (my $ref = $q->fetchrow_hashref) {
my $switch = $ref->{'switch'};
+
my $ip = $ref->{'ip'};
$ping->host_add($ip);
$ip_to_switch{$ip} = $switch;
+
+ my $secondary_ip = $ref->{'secondary_ip'};
+ if (defined($secondary_ip)) {
+ $ping->host_add($secondary_ip);
+ $secondary_ip_to_switch{$secondary_ip} = $switch;
+ }
}
my $result = $ping->ping();
die $ping->get_error if (!defined($result));
@@ -35,13 +43,23 @@ while (1) {
$dbh->do('COPY ping (switch, latency_ms) FROM STDIN'); # date is implicitly now.
while (my ($ip, $latency) = each %$result) {
my $switch = $ip_to_switch{$ip};
- if (!defined($latency)) {
- $dbh->pg_putcopydata("$switch\t\\N\n");
- } else {
- $dbh->pg_putcopydata("$switch\t$latency\n");
- }
+ next if (!defined($switch));
+
+ $latency //= "\\N";
+ $dbh->pg_putcopydata("$switch\t$latency\n");
}
$dbh->pg_putcopyend();
+
+ $dbh->do('COPY ping_secondary_ip (switch, latency_ms) FROM STDIN'); # date is implicitly now.
+ while (my ($ip, $latency) = each %$result) {
+ my $switch = $secondary_ip_to_switch{$ip};
+ next if (!defined($switch));
+
+ $latency //= "\\N";
+ $dbh->pg_putcopydata("$switch\t$latency\n");
+ }
+ $dbh->pg_putcopyend();
+
$dbh->commit;
# ping linknets