From f2a6303dd8105475fcea676bead10f52df36f639 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Apr 2014 18:43:53 +0200 Subject: Ping linknets, and show that on the map. --- web/nms.gathering.org/ping-json.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/ping-json.pl') diff --git a/web/nms.gathering.org/ping-json.pl b/web/nms.gathering.org/ping-json.pl index 47b5cc2..78e795a 100755 --- a/web/nms.gathering.org/ping-json.pl +++ b/web/nms.gathering.org/ping-json.pl @@ -13,7 +13,15 @@ $q->execute(); my %json = (); while (my $ref = $q->fetchrow_hashref()) { - $json{$ref->{'switch'}} = $ref->{'latency_ms'}; + $json{'switches'}{$ref->{'switch'}} = $ref->{'latency_ms'}; } + +my $lq = $dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE updated >= NOW() - INTERVAL '15 secs' ORDER BY linknet, updated DESC;"); +$lq->execute(); +while (my $ref = $lq->fetchrow_hashref()) { + $json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; +} + +$q->execute(); print $cgi->header(-type=>'text/json; charset=utf-8'); print JSON::XS::encode_json(\%json); -- cgit v1.2.3