diff options
| -rwxr-xr-x | web/nms.gathering.org/api/public/dhcp | 1 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/public/switch-state | 2 | ||||
| -rw-r--r-- | web/nms.gathering.org/index.html | 15 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-map-handlers.js | 74 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms.js | 12 | 
5 files changed, 85 insertions, 19 deletions
| diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp index d432af0..91d52af 100755 --- a/web/nms.gathering.org/api/public/dhcp +++ b/web/nms.gathering.org/api/public/dhcp @@ -7,6 +7,7 @@ use strict;  use warnings;  use Data::Dumper; +nms::web::setwhen('60m');  my $q = $nms::web::dbh->prepare('select distinct on (sysname) extract(epoch from date_trunc(\'second\',time)) as time,sysname from dhcp join switches on dhcp.switch = switches.switch where ' . $nms::web::when . ' order by sysname,time desc;');  $q->execute();  while ( my $ref = $q->fetchrow_hashref() ) { diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 6f7573c..4907449 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -20,7 +20,7 @@ while ( my $ref = $q->fetchrow_hashref() ) {  		my %port = %{$data{'ports'}{$porti}};  		my $smallport = $porti;  		$smallport =~ s/[0-9-].*$//; -		if ($porti =~  /ge-0\/0\/4[4-7]/) { +		if ($porti =~  /ge-0\/0\/4[4-7]$/) {  			$json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};  			$json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};  			if ($port{'ifOperStatus'} eq "up") { diff --git a/web/nms.gathering.org/index.html b/web/nms.gathering.org/index.html index 02ae93c..b244d1b 100644 --- a/web/nms.gathering.org/index.html +++ b/web/nms.gathering.org/index.html @@ -59,9 +59,10 @@  	      <ul class="dropdown-menu" role="menu">  		<li><a href="#ping" onclick="setUpdater(handler_ping)">Ping map</a></li>  		<li><a href="#uplink" onclick="setUpdater(handler_uplinks)">Uplink map</a></li> +		<li><a href="#dhcp" onclick="setUpdater(handler_dhcp)">DHCP map</a></li> +		<li><a href="#comment" onclick="setUpdater(handler_comment)">Comment spotter</a></li>  		<li><a href="#temp" onclick="setUpdater(handler_temp)">Temperature map</a></li>  		<li><a href="#traffic" onclick="setUpdater(handler_traffic)">Traffic map</a></li> -		<li><a href="#comment" onclick="setUpdater(handler_comment)">Comment spotter</a></li>  		<li><a href="#traffictot" onclick="setUpdater(handler_traffic_tot)">Total switch traffic</a></li>  		<li><a href="#disco" onclick="setUpdater(handler_disco)">DISCO</a></li>  		<li class="divider"> </li> @@ -145,22 +146,26 @@  		</tr>  		<tr>  		  <td>3</td> -		  <td>View temperature map</td> +		  <td>View DHCP map</td>  		</tr>  		<tr>  		  <td>4</td> -		  <td>View uplink traffic map</td> +		  <td>View comment spotter map</td>  		</tr>  		<tr>  		  <td>5</td> -		  <td>View comment spotter map</td> +		  <td>View temperature map</td>  		</tr>  		<tr>  		  <td>6</td> -		  <td>View total switch traffic map</td> +		  <td>View uplink traffic map</td>  		</tr>  		<tr>  		  <td>7</td> +		  <td>View total switch traffic map</td> +		</tr> +		<tr> +		  <td>9</td>  		  <td>View Disco map</td>  		</tr>  		<tr> diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index 04aabd2..1ae5d72 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -49,6 +49,12 @@ var handler_traffic_tot = {  	name:"Switch traffic map"  }; +var handler_dhcp = { +	init:dhcpInit, +	tag:"dhcp", +	name:"DHCP map" +}; +  var handler_disco = {  	init:discoInit,  	tag:"disco", @@ -68,7 +74,8 @@ var handlers = [  	handler_traffic,  	handler_disco,  	handler_comment, -	handler_traffic_tot +	handler_traffic_tot, +	handler_dhcp  	];  /* @@ -95,12 +102,12 @@ function uplinkUpdater()  		if (uplinks == 0) {  			nmsMap.setSwitchColor(sw,"white"); -		} else if (nuplinks == uplinks) { -			nmsMap.setSwitchColor(sw,green); -		} else if (nuplinks - uplinks == 1) { -			nmsMap.setSwitchColor(sw, orange); -		} else if (nuplinks - uplinks == 2) { +		} else if (uplinks == 1) {  			nmsMap. setSwitchColor(sw, red); +		} else if (uplinks == 2) { +			nmsMap.setSwitchColor(sw, orange); +		} else if (uplinks == 3) { +			nmsMap.setSwitchColor(sw,green);  		} else if (uplinks > 3) {  			nmsMap.setSwitchColor(sw, blue);  		} @@ -115,9 +122,9 @@ function uplinkInit()  	nmsData.addHandler("switches","mapHandler",uplinkUpdater);  	nmsData.addHandler("switchstate","mapHandler",uplinkUpdater);  	setLegend(1,"white","0 uplinks");	 -	setLegend(2,red,"2 missing");	 -	setLegend(3,orange,"1 missing");	 -	setLegend(4,green,"0 missing");	 +	setLegend(2,red,"1 uplink");	 +	setLegend(3,orange,"2 uplinks");	 +	setLegend(4,green,"3 uplinks");	  	setLegend(5,blue,"4 uplinks");	  } @@ -337,6 +344,55 @@ function commentInit()  	setLegend(5,green ,"Old/inactive only");	  } +function getDhcpColor(stop) +{ +	stop = parseInt(stop); +	stop = stop * 0.85; +	if (stop < 0) +		stop = 1000; +	if (stop > 1000) +		stop = 1000; +	return getColorStop(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; +	} +	try { +	for (var sw in nmsData.switches.switches) { +		var c = "white"; +		if (nmsData.dhcp.dhcp[sw] == undefined) { +			nmsMap.setSwitchColor(sw,c); +			continue; +		} +		var s = nmsData.dhcp.dhcp[sw]; +		var then = parseInt(s); +		c = getDhcpColor(now - then); +		nmsMap.setSwitchColor(sw, c); +	} +	} catch(e) { +		console.log(e); +	} +} + +function dhcpInit() +{ +	drawGradient([green,lightgreen,orange,red]); +	nmsData.addHandler("dhcp","mapHandler",dhcpUpdater); +	setLegend(1,"white","Undefined"); +	setLegend(2,getDhcpColor(1),"1 Second old"); +	setLegend(3,getDhcpColor(300),"300 Seconds old"); +	setLegend(4,getDhcpColor(900),"900 Seconds old"); +	setLegend(5,getDhcpColor(1200),"1200 Seconds old"); +} +  /*   * Testing-function to randomize colors of linknets and switches   */ diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js index 12823eb..49cacde 100644 --- a/web/nms.gathering.org/js/nms.js +++ b/web/nms.gathering.org/js/nms.js @@ -463,6 +463,7 @@ function initNMS() {  	nmsData.registerSource("switches","/api/public/switches");  	nmsData.registerSource("switchstate","/api/public/switch-state");  	nmsData.registerSource("dhcpsummary","/api/public/dhcp-summary"); +	nmsData.registerSource("dhcp","/api/public/dhcp");  	// 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 @@ -524,18 +525,21 @@ function setMapModeFromN(e,key)  			setUpdater(handler_uplinks);  			break;  		case '3': -			setUpdater(handler_temp); +			setUpdater(handler_dhcp);  			break;  		case '4': -			setUpdater(handler_traffic); +			setUpdater(handler_comment);  			break;  		case '5': -			setUpdater(handler_comment); +			setUpdater(handler_temp);  			break;  		case '6': -			setUpdater(handler_traffic_tot); +			setUpdater(handler_traffic);  			break;  		case '7': +			setUpdater(handler_traffic_tot); +			break; +		case '9':  			setUpdater(handler_disco);  			break;  	} | 
