diff options
-rw-r--r-- | web/nms.gathering.org/nms2/index.html (renamed from web/nms.gathering.org/nms2/map.html) | 9 | ||||
-rw-r--r-- | web/nms.gathering.org/nms2/js/nms.js (renamed from web/nms.gathering.org/nms2/map.js) | 45 | ||||
-rwxr-xr-x | web/nms.gathering.org/ping-json2.pl | 13 | ||||
-rwxr-xr-x | web/nms.gathering.org/port-state.pl | 11 |
4 files changed, 67 insertions, 11 deletions
diff --git a/web/nms.gathering.org/nms2/map.html b/web/nms.gathering.org/nms2/index.html index 7e40964..dc20034 100644 --- a/web/nms.gathering.org/nms2/map.html +++ b/web/nms.gathering.org/nms2/index.html @@ -48,6 +48,8 @@ <li class="divider"> </li> <li><a href="#" onclick="toggleNightMode()" title="Add 'nightMode' anywhere in the url to auto-enable">Toggle Night Mode</a></li> <li class="divider"> </li> + <li><a href="#" onclick="document.getElementById('nowPickerBox').style.display = 'block';">Travel in time</a></li> + <li class="divider"> </li> <li><input type="range" id="scaler" name="points" min="0.5" max="3" step="0.01" onchange="scaleChange()" /></li> <li><a href="#">Scale: <div id="scaler-text"></div></a></li> </ul> @@ -62,6 +64,11 @@ <div class="container-fluid"> <div class="panel" style="position: fixed; z-index: 10000;"> <div class="span4"> + <div id="nowPickerBox" style="display:none; background: + white; border: 1px solid #000000;" > + <input type="text" class="form-control" placeholder="YYYY-MM-DD hh:mm:ss" id="nowPicker" value="" /> + <button class="btn btn-default" onclick="changeNow();">Travel</button> + </div> <div id="info-switch-parent" style="background: silver"> <table class="table" id="info-switch-table"></table> </div> @@ -90,7 +97,7 @@ var draw_linknets = true; var can_edit = false; </script> - <script type="text/javascript" src="map.js"></script> + <script type="text/javascript" src="js/nms.js"></script> <script type="text/javascript"> updatePorts(); updatePing(); diff --git a/web/nms.gathering.org/nms2/map.js b/web/nms.gathering.org/nms2/js/nms.js index db5d475..101f2b1 100644 --- a/web/nms.gathering.org/nms2/map.js +++ b/web/nms.gathering.org/nms2/js/nms.js @@ -12,6 +12,7 @@ var nms = { switch_color:{}, damage:false, drawText:true, + now:false, did_update:false // Set to 'true' after we've done some basic updating }; @@ -22,7 +23,7 @@ var counters = { var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); -var fontSize = 12; +var fontSize = 16; var fontFace = "Arial Black"; var orig = { width:1920, @@ -90,6 +91,36 @@ function toggleNightMode() { setNightMode(!nms.nightMode); } +function checkNow(now) { + if (Date.parse(now)) { + var d = new Date(Date.parse(now)); + var str = d.getFullYear() + "-" + (parseInt(d.getMonth())+1) + "-" + d.getDate() + " "; + str += d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds(); + return str; + + } + if (now == "") + return ""; + return false; +} + +function changeNow() { + var newnow = checkNow(document.getElementById("nowPicker").value); + if (!newnow) { + alert('Bad date-field in time travel field'); + return; + } + if (newnow == "") + newnow = false; + + nms.now = newnow; + updatePorts(); + var boxHide = document.getElementById("nowPickerBox"); + if (boxHide) { + boxHide.style.display = "none"; + } +} + /* * Hide switch info-box */ @@ -484,7 +515,7 @@ function updatePing() { $.ajax({ type: "GET", - url: "/ping-json2.pl", + url: "/ping-json2.pl?now=" + nms.now, dataType: "text", success: function (data, textStatus, jqXHR) { nms.ping_data = JSON.parse(data); @@ -498,9 +529,12 @@ function updatePing() */ function updatePorts() { + var now = ""; + if (nms.now) + now = "?now=" + nms.now; $.ajax({ type: "GET", - url: "/port-state.pl", + url: "/port-state.pl"+ now , dataType: "text", success: function (data, textStatus, jqXHR) { var switchdata = JSON.parse(data); @@ -509,9 +543,12 @@ function updatePorts() initialUpdate(); } }); + now=""; + if (nms.now) + now = "&now=" + nms.now; $.ajax({ type: "GET", - url: "/port-state.pl?time=5m", + url: "/port-state.pl?time=5m" + now, dataType: "text", success: function (data, textStatus, jqXHR) { var switchdata = JSON.parse(data); diff --git a/web/nms.gathering.org/ping-json2.pl b/web/nms.gathering.org/ping-json2.pl index ee3d059..a24c589 100755 --- a/web/nms.gathering.org/ping-json2.pl +++ b/web/nms.gathering.org/ping-json2.pl @@ -7,21 +7,28 @@ use nms; my $cgi = CGI->new; my $dbh = nms::db_connect(); + +my $now = "now()"; +if ($cgi->param('now') != undef) { + $now = "'" . $cgi->param('now') . "'::timestamp "; +} +my $when =" updated > " . $now . " - '15 secs'::interval and updated < " . $now . " "; + my %json = (); -my $q = $dbh->prepare("SELECT DISTINCT ON (switch,sysname) switch,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE updated >= NOW() - INTERVAL '15 secs' ORDER BY switch,sysname, updated DESC;"); +my $q = $dbh->prepare("SELECT DISTINCT ON (switch,sysname) switch,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE $when ORDER BY switch,sysname, updated DESC;"); $q->execute(); while (my $ref = $q->fetchrow_hashref()) { $json{'switches'}{$ref->{'sysname'}}{'latency'} = $ref->{'latency_ms'}; } -my $qs = $dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE updated >= NOW() - INTERVAL '15 secs' ORDER BY switch, updated DESC;"); +my $qs = $dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE $when ORDER BY switch, updated DESC;"); $qs->execute(); while (my $ref = $qs->fetchrow_hashref()) { $json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $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;"); +my $lq = $dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE $when ORDER BY linknet, updated DESC;"); $lq->execute(); while (my $ref = $lq->fetchrow_hashref()) { $json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; diff --git a/web/nms.gathering.org/port-state.pl b/web/nms.gathering.org/port-state.pl index a7b2f05..0821cde 100755 --- a/web/nms.gathering.org/port-state.pl +++ b/web/nms.gathering.org/port-state.pl @@ -14,11 +14,16 @@ my $dbh = nms::db_connect(); my $switch = $cgi->param('switch'); my @ports = split(",",$cgi->param('ports')); my $cin = $cgi->param('time'); -my $when =" time > now() - '5m'::interval"; +my $now = "now()"; +if ($cgi->param('now') != undef) { + $now = "'" . $cgi->param('now') . "'::timestamp "; +} + +my $when =" time > " . $now . " - '5m'::interval and time < " . $now . " "; my %json = (); if (defined($cin)) { - $when = " time < now() - '$cin'::interval and time > now() - ('$cin'::interval + '15m'::interval) "; + $when = " time < " . $now . " - '$cin'::interval and time > ". $now . " - ('$cin'::interval + '15m'::interval) "; } my $query = 'select distinct on (switch,ifname,ifhighspeed,ifhcoutoctets,ifhcinoctets) extract(epoch from date_trunc(\'second\',time)) as time,switch,ifname,max(ifhighspeed) as ifhighspeed,max(ifhcinoctets) as ifhcinoctets,max(ifhcoutoctets) as ifhcoutoctets,switch,sysname from polls natural join switches where ' . $when . ' '; @@ -48,7 +53,7 @@ while (my $ref = $q->fetchrow_hashref()) { #print Dumper(%json); my $q2 = $dbh->prepare('select switch,sysname,placement,zorder,ip,switchtype,poll_frequency,community,last_updated from switches natural join placements'); -my $q3 = $dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches order by switch,time desc'); +my $q3 = $dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $when . ' order by switch,time desc'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { |