aboutsummaryrefslogtreecommitdiffstats
path: root/web/api/public/ping
blob: 52dffbce8aefadb736841514112afe491f6d7cde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/bin/perl
use lib '/opt/gondul/include';
use strict;
use warnings;
use nms::web;

nms::web::setwhen('25s');

my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::now . " - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where "
        . $nms::web::when . " group by switch)");

$q->execute();
while (my $ref = $q->fetchrow_hashref()) {
    $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency4'} = $ref->{'latency_ms'};
    # Get seconds, without decimlas, from timestamp.
    # '00:01:01.435601' => 61 seconds.
    my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} );
    $nms::web::json{'switches'}{$ref->{'sysname'}}{'age4'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'};
}

my $q2 = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::now . " - time) as age,sysname, latency_ms FROM ping_secondary_ip NATURAL JOIN switches WHERE time in (select max(time) from ping where "
        . $nms::web::when . " group by switch)");

$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
    $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency6'} = $ref->{'latency_ms'};
    # Get seconds, without decimlas, from timestamp.
    # '00:01:01.435601' => 61 seconds.
    my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} );
    $nms::web::json{'switches'}{$ref->{'sysname'}}{'age6'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'};
}

$nms::web::cc{'max-age'} = "1";
$nms::web::cc{'stale-while-revalidate'} = "5";
finalize_output();