aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly.no>2016-03-31 20:44:38 +0200
committerKristian Lyngstol <kly@kly.no>2016-03-31 20:44:38 +0200
commit51e9872f4ac5db633c12862dec951e0b91b1b132 (patch)
treeff156c63ba964357e955bfcf4634f0d02ea12609
parent37d9d6b9d78fcda093dfc37dc36ed8eb0eb09cd2 (diff)
NMS: Fix historic review, part one
The actual replay might still be bugged, but fixed-point review works.
-rwxr-xr-xinclude/nms/web.pm8
-rwxr-xr-xweb/nms.gathering.org/api/public/ping2
-rw-r--r--web/nms.gathering.org/js/nms-map-handlers.js3
3 files changed, 6 insertions, 7 deletions
diff --git a/include/nms/web.pm b/include/nms/web.pm
index 889e774..7c9339e 100755
--- a/include/nms/web.pm
+++ b/include/nms/web.pm
@@ -15,7 +15,7 @@ package nms::web;
use base 'Exporter';
our %get_params;
our %json;
-our @EXPORT = qw(finalize_output json $dbh db_safe_quote %get_params get_input %json);
+our @EXPORT = qw(finalize_output now json $dbh db_safe_quote %get_params get_input %json);
our $dbh;
our $now;
our $when;
@@ -66,7 +66,7 @@ sub setwhen {
$offset = $_[1];
}
if (defined($get_params{'now'})) {
- $now = db_safe_quote('now') . "::timestamp ";
+ $now = db_safe_quote('now') . "::timestamp with time zone ";
$cc{'max-age'} = "3600";
}
$now = "(" . $now . " - '" . $offset . "'::interval)";
@@ -77,10 +77,10 @@ sub finalize_output {
my $query;
my $hash = Digest::SHA::sha512_base64(FreezeThaw::freeze(%json));
$dbh->commit;
- $query = $dbh->prepare('select to_char(' . $now . ', \'YYYY-MM-DD"T"HH24:MI:SS\') as time;');
+ $query = $dbh->prepare('select extract(epoch from date_trunc(\'seconds\', ' . $now . ')) as time;');
$query->execute();
- $json{'time'} = $query->fetchrow_hashref()->{'time'};
+ $json{'time'} = int($query->fetchrow_hashref()->{'time'});
$json{'hash'} = $hash;
printcc;
diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping
index 5d1037c..811708d 100755
--- a/web/nms.gathering.org/api/public/ping
+++ b/web/nms.gathering.org/api/public/ping
@@ -6,7 +6,7 @@ use nms::web;
nms::web::setwhen('15s');
-my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (now() - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where "
+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();
diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js
index 474e8ef..a7672a3 100644
--- a/web/nms.gathering.org/js/nms-map-handlers.js
+++ b/web/nms.gathering.org/js/nms-map-handlers.js
@@ -373,14 +373,13 @@ function getDhcpColor(stop)
function dhcpUpdater()
{
- var realnow = Date.now();
- var now = Math.floor(realnow / 1000);
if (nmsData.dhcp == undefined || nmsData.dhcp.dhcp == undefined) {
return
}
if (nmsData.switches == undefined || nmsData.switches.switches == undefined) {
return;
}
+ var now = nmsData.dhcp.time;
try {
for (var sw in nmsData.switches.switches) {
var c = blue;