diff options
Diffstat (limited to 'web')
| -rwxr-xr-x | web/nms.gathering.org/api/public/ping | 12 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-data.js | 12 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-map-handlers.js | 31 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms.js | 19 | 
4 files changed, 53 insertions, 21 deletions
| diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping index f13a03b..bf92440 100755 --- a/web/nms.gathering.org/api/public/ping +++ b/web/nms.gathering.org/api/public/ping @@ -2,10 +2,18 @@  use lib '../../../../include';  use nms::web; -my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) time,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " . $nms::web::when . " group by switch)"); +#nms::web::setwhen('1s'); + +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 " . $nms::web::when . " group by switch)");  $q->execute();  while (my $ref = $q->fetchrow_hashref()) {  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'latency'} = $ref->{'latency_ms'}; +	# This isn't pretty, feel free to fix, but I want age == seconds +	# without decimals. +	my ($h,$m,$ss) = split(':', $ref->{'age'}); +	my ($s,undef) = split('\.', "$ss"); +	 +	$nms::web::json{'switches'}{$ref->{'sysname'}}{'age'} = ($h*60*60) + ($m*60) + $s;#  $$ref->{'age'};  }  my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " . $nms::web::when .  " ORDER BY switch, time DESC;"); @@ -20,8 +28,6 @@ while (my $ref = $lq->fetchrow_hashref()) {  	$nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ];  } -$q->execute(); -  $nms::web::cc{'max-age'} = "1";  $nms::web::cc{'stale-while-revalidate'} = "5";  finalize_output(); diff --git a/web/nms.gathering.org/js/nms-data.js b/web/nms.gathering.org/js/nms-data.js index ef41a3a..155b5a8 100644 --- a/web/nms.gathering.org/js/nms-data.js +++ b/web/nms.gathering.org/js/nms-data.js @@ -168,6 +168,18 @@ nmsData.unregisterHandler = function(name, id) {   * after a comment is posted).   */  nmsData.updateSource = function(name) { +	/* +	 * See comment in nms.js nmsINIT(); +	 */ +	if (name == "ticker" ) { +		for (var i in nmsData._sources[name].cbs) { +			var tmp = nmsData._sources[name].cbs[i]; +			if (tmp.cb != undefined) { +				tmp.cb(tmp.cbdata); +			} +		} +		return; +	}  	this._genericUpdater(name, true);  } diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index 0126c38..e6b9103 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -162,9 +162,6 @@ function trafficUpdater()  	}  } -/* - * Init-function for uplink map - */  function trafficTotInit()  {  	var m = 1024 * 1024 / 8; @@ -250,23 +247,20 @@ function tempInit()  function pingUpdater()  { -	if (!nms.ping_data || !nms.ping_data["switches"]) { +	if (nmsData.switches == undefined || nmsData.switches.switches == undefined) {  		return;  	} -	for (var sw in nms.switches_now["switches"]) { -		var c = blue; -		if (nms.ping_data['switches'] && nms.ping_data['switches'][sw]) -			c = gradient_from_latency(nms.ping_data["switches"][sw]["latency"]); -		setSwitchColor(sw, c); -	} -	for (var ln in nms.switches_now["linknets"]) { -		var c1 = blue; -		var c2 = c1; -		if (nms.ping_data['linknets'] && nms.ping_data['linknets'][ln]) { -			c1 = gradient_from_latency(nms.ping_data["linknets"][ln][0]); -			c2 = gradient_from_latency(nms.ping_data["linknets"][ln][1]); +	for (var sw in nmsData.switches.switches) { +		try { +			if (nmsData.ping.switches[sw].age > 0) { +				c = red; +			} else { +				c = gradient_from_latency(nmsData.ping.switches[sw].latency); +			} +			nmsMap.setSwitchColor(sw, c); +		} catch (e) { +			nmsMap.setSwitchColor(sw, blue);  		} -		setLinknetColors(ln, c1, c2);  	}  } @@ -278,6 +272,9 @@ function pingInit()  	setLegend(3,gradient_from_latency(60),"60ms");	  	setLegend(4,gradient_from_latency(100),"100ms");	  	setLegend(5,gradient_from_latency(undefined) ,"No response");	 +	nmsData.addHandler("ping","mapHandler",pingUpdater); +	nmsData.addHandler("switches","mapHandler",pingUpdater); +	nmsData.addHandler("ticker", "mapHandler", pingUpdater);  }  function commentUpdater() diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js index 0484ffa..025fab9 100644 --- a/web/nms.gathering.org/js/nms.js +++ b/web/nms.gathering.org/js/nms.js @@ -320,7 +320,17 @@ function setUpdater(fo)  {  	nmsMap.reset();  	nmsData.unregisterHandlerWildcard("mapHandler"); -	fo.init(); +	try { +		fo.init(); +	} catch (e) { +		/* +		 * This can happen typically on initial load where the data +		 * hasn't been retrieved yet. Instead of breaking the +		 * entire init-process, just bail out here. +		 */ +		console.log("Possibly broken handler: " + fo.name); +		console.log(e); +	}  	var foo = document.getElementById("updater_name");  	foo.innerHTML = fo.name + "   ";  	document.location.hash = fo.tag; @@ -455,6 +465,13 @@ function initNMS() {  	nmsData.registerSource("ping", "/api/public/ping");  	nmsData.registerSource("switches","/api/public/switches");  	nmsData.registerSource("switchstate","/api/public/switch-state"); +	 +	// This is a magic dummy-source, it's purpose is to give a unified +	// way to get ticks every second. It is mainly meant to allow map +	// handlers to register for ticks so they will execute without data +	// (and thus notice stale data instead of showing a green ping-map +	// despite no pings) +	nmsData.registerSource("ticker","bananabananbanana");  	// Private	  	nmsData.registerSource("snmp","/api/private/snmp"); | 
