diff options
| author | Kristian Lyngstol <kly@kly@.no> | 2016-03-24 21:15:50 +0100 | 
|---|---|---|
| committer | Kristian Lyngstol <kly@kly@.no> | 2016-03-24 21:15:50 +0100 | 
| commit | 7ac4551ed94c1f1393bc69e595a90dbe15bc8f6c (patch) | |
| tree | d68fbc18f69cc33aaabec82b1092ba147a32b346 /web | |
| parent | f0a12faa1dceb7c21e1688164342aa58e8f136f2 (diff) | |
NMS: Update public api
Diffstat (limited to 'web')
| -rwxr-xr-x | web/nms-public.gathering.org/api/public/switch-state | 2 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms-info-box.js | 154 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms-map-handlers.js | 47 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms.js | 6 | 
4 files changed, 189 insertions, 20 deletions
diff --git a/web/nms-public.gathering.org/api/public/switch-state b/web/nms-public.gathering.org/api/public/switch-state index 62e497c..0e28cfd 100755 --- a/web/nms-public.gathering.org/api/public/switch-state +++ b/web/nms-public.gathering.org/api/public/switch-state @@ -59,7 +59,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) {  	for my $porti (keys %{$data{'ports'}}) {  		my %port = %{$data{'ports'}{$porti}};  		my $smallport = $porti; -		if (not $smallport =~ m/^ae/) { +		if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) {  			$smallport =~ s/[0-9-].*$//;  		} else {  			$json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; diff --git a/web/nms-public.gathering.org/js/nms-info-box.js b/web/nms-public.gathering.org/js/nms-info-box.js index 0481420..a718f78 100644 --- a/web/nms-public.gathering.org/js/nms-info-box.js +++ b/web/nms-public.gathering.org/js/nms-info-box.js @@ -37,10 +37,10 @@ nmsInfoBox.showWindow = function (windowName,argument) {  /*   * Refresh the active window   */ -nmsInfoBox.refresh = function() { +nmsInfoBox.refresh = function(argument) {  	if(!nmsInfoBox._window)  		return; -  nmsInfoBox._show(); +  nmsInfoBox._show(argument);  };  nmsInfoBox.update = function(argument) {  	if(!nmsInfoBox._window) @@ -57,7 +57,8 @@ nmsInfoBox._show = function(argument) {    nmsData.addHandler("smanagement","switchshower",nmsInfoBox.update,'smanagement');    nmsData.addHandler("snmp","switchshower",nmsInfoBox.update,'snmp'); -  this._window.load(argument); +	if(argument != "soft") +		this._window.load(argument);    this._container = document.getElementById("info-panel-container");    var panel = document.createElement("div"); @@ -209,7 +210,17 @@ nmsInfoBox._windowTypes.switchInfo = {  		}  	},    getTitle: function() { -    return '<h4>' + this.sw + '</h4><button type="button" class="edit btn btn-xs btn-warning" onclick="nmsInfoBox._windowTypes.switchInfo.showEdit(\'' + this.sw + '\');">Edit</button> <button type="button" class="comments btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showComments(\'' + this.sw + '\');">Comments</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'ports\');">Ports</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'misc\');">Misc</button>'; +		var sshButton = ''; +		try { +			var mgmt = nmsInfoBox._window.swm.mgmt_v4_addr; +			sshButton = mgmt.split("/")[0]; +		} catch(e) { +			console.log(e); +		} +		if(sshButton != null && sshButton != undefined && sshButton != '') { +			sshButton = ' <button type="button" class="ssh btn btn-xs btn-default"><a href="ssh://' + sshButton + '">SSH</a></button>'; +		} +    return '<h4>' + this.sw + '</h4><button type="button" class="edit btn btn-xs btn-warning" onclick="nmsInfoBox._windowTypes.switchInfo.showEdit(\'' + this.sw + '\');">Edit</button> <button type="button" class="comments btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showComments(\'' + this.sw + '\');">Comments</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'ports\');">Ports</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'misc\');">Misc</button>' + sshButton;    },    getContent: function() {      return this.content; @@ -358,6 +369,126 @@ nmsInfoBox._windowTypes.switchInfo = {  };  /* + * Window type: Show inventory listing + * + * Basic window that displays a list of all devices with simple summary information + * + * TODO: Set up more complex views with more columns, sorting, etc. + * + */ +nmsInfoBox._windowTypes.inventoryListing = { +  content:  '', +  childContent: false, +	activeView: '', +	activeFilter: '', +  getTitle: function() { +    return '<h4>Inventory listing</h4><button type="button" class="distro-name btn btn-xs btn-default" onclick="nmsInfoBox.showWindow(\'inventoryListing\',\'distro_name\');">Distro name</button> <button type="button" class="distro-name btn btn-xs btn-default" onclick="nmsInfoBox.showWindow(\'inventoryListing\',\'sysDescr\');">System Description</button>'; +  }, +  getContent: function() { +    return this.content; +  }, +  getChildContent: function() { +    return this.childContent; +  }, +	setFilter: function(filter) { +		this.activeFilter = filter.toLowerCase(); +		nmsInfoBox._windowTypes.inventoryListing.load("refresh"); +	}, +	getFilter: function() { +		return this.activeFilter; +	}, +  load: function(list) { +		var hasSnmp = false; +		var targetArray = []; +		var listTitle = ''; +		var needRefresh = false; +		var needSnmp = false; +		var contentObj = document.createElement("div"); +		var inputObj = document.createElement("div"); +		inputObj.innerHTML = '<div class="input-group"><input type="text" class="form-control" placeholder="Filter" id="inventorylisting-filter" value="' + this.activeFilter + '" onkeyup="if (event.keyCode == 13) {nmsInfoBox._windowTypes.inventoryListing.setFilter(document.getElementById(\'inventorylisting-filter\').value);}"><span class=\"input-group-btn\"><button class="btn btn-default" onclick="nmsInfoBox._windowTypes.inventoryListing.setFilter(document.getElementById(\'inventorylisting-filter\').value);">Filtrer</button></span></div>'; +		contentObj.appendChild(inputObj); + + +		if(!nmsData.switches || !nmsData.switches.switches) +			return; +		if(!(!nmsData.snmp || !nmsData.snmp.snmp)) { +			hasSnmp = true; +		} +		if(list == "refresh") { +			list = this.activeView; +			needRefresh = true; +		} + +		switch (list) { +			case 'distro_name': +				listTitle = 'Distro names'; +				break; +			case 'sysDescr': +				if(hasSnmp) +				listTitle = 'System description'; +				needSnmp = true; +				break; +			default: +				listTitle = 'Distro names'; +				list = 'distro_name'; +		} +		this.activeView = list; + +		if(needSnmp && !hasSnmp) { +			this.content = "No SNMP data loaded. Reloading shortly."; +			nmsData.addHandler("snmp","inventoryListing",nmsInfoBox._windowTypes.inventoryListing.update,"snmp-request"); +			return; +		} + +		var resultArray = []; +		for(var sw in nmsData.switches.switches) { +			var value = ''; +			if(this.activeFilter != '') { +				if(sw.toLowerCase().indexOf(this.activeFilter) == -1 && !nmsInfoBox._searchSmart(this.activeFilter,sw)) +					continue; +			} +			try { +				switch (list) { +					case 'distro_name': +						value = nmsData.switches.switches[sw]["distro_name"]; +						break; +					case 'sysDescr': +						value = nmsData.snmp.snmp[sw]["misc"]["sysDescr"][0]; +						break; +				} +			} catch (e) { +				//console.log(e); +			} +			resultArray.push([sw, value]); +		} + +		resultArray.sort(); + +		var infotable = nmsInfoBox._makeTable(resultArray,listTitle); +		infotable.id = "inventory-table"; + +		contentObj.appendChild(infotable); +		this.content = contentObj; +		if(needRefresh) +			nmsInfoBox.refresh("soft"); +  }, +	update: function(type) { +		if(type == "snmp-request") { +			nmsData.unregisterHandler("snmp","inventoryListing"); +			nmsInfoBox._windowTypes.inventoryListing.load("refresh"); +		} +	}, +  unload: function() { +		nmsData.unregisterHandler("snmp","inventoryListing"); +		this.content = ''; +		this.activeView = ''; +		this.activeFilter = ''; +  }, +  save: function() { +	} +}; + +/*   * Click a switch and display it   * it.   */ @@ -443,9 +574,11 @@ nmsInfoBox._makeCommentTable = function(content) {  nmsInfoBox._searchSmart = function(id, sw) {  	try { -		if (nmsData.switches.switches[sw].distro_name == id) { -			return true; -		} +		try { +			if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) { +				return true; +			} +		} catch (e) {}  		if (id.match("active")) {  			var limit = id;  			limit = limit.replace("active>",""); @@ -484,7 +617,7 @@ nmsInfoBox._searchSmart = function(id, sw) {  				return true;  			}  		} catch (e) {} -		if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) { +		if (nmsData.snmp.snmp[sw].misc.sysDescr[0].toLowerCase().match(id)) {  			return true;  		}  	} catch (e) { @@ -502,12 +635,12 @@ nmsInfoBox._search = function() {  	var id = false;  	var matches = [];  	if (el) { -		id = el.value; +		id = el.value.toLowerCase();  	}  	if(id) {  		nmsMap.enableHighlights();  		for(var sw in nmsData.switches.switches) { -			if(sw.indexOf(id) > -1) { +			if(sw.toLowerCase().indexOf(id) > -1) {  				matches.push(sw);  				nmsMap.setSwitchHighlight(sw,true);  			} else if (nmsInfoBox._searchSmart(id,sw)) { @@ -547,7 +680,6 @@ nmsInfoBox._searchKeyListener = function(e) {  	}  }; -  nmsInfoBox._nullBlank = function(x) {  	if (x == null || x == false || x == undefined)  		return ""; diff --git a/web/nms-public.gathering.org/js/nms-map-handlers.js b/web/nms-public.gathering.org/js/nms-map-handlers.js index 5537332..868d26d 100644 --- a/web/nms-public.gathering.org/js/nms-map-handlers.js +++ b/web/nms-public.gathering.org/js/nms-map-handlers.js @@ -73,6 +73,12 @@ var handler_snmp = {  	name:"SNMP state"  }; +var handler_cpu = { +	init:cpuInit, +	tag:"cpu", +	name:"CPU utilization" +}; +  var handlers = [  	handler_uplinks,  	handler_temp, @@ -82,7 +88,8 @@ var handlers = [  	handler_comment,  	handler_traffic_tot,  	handler_dhcp, -	handler_snmp +	handler_snmp, +	handler_cpu  	];  /* @@ -145,9 +152,9 @@ function trafficInit()  	var m = 1024 * 1024 / 8;  	drawGradient([lightgreen,green,orange,red]);  	setLegend(1,colorFromSpeed(0),"0 (N/A)");	 -	setLegend(5,colorFromSpeed(2000 * m) , "2000Mb/s");	 -	setLegend(4,colorFromSpeed(1500 * m),"1500Mb/s");	 -	setLegend(3,colorFromSpeed(500 * m),"500Mb/s");	 +	setLegend(5,colorFromSpeed(1100 * m) , "1100Mb/s");	 +	setLegend(4,colorFromSpeed(600 * m),"600Mb/s");	 +	setLegend(3,colorFromSpeed(300 * m),"300Mb/s");	  	setLegend(2,colorFromSpeed(10 * m),"10Mb/s");	  } @@ -166,8 +173,10 @@ function trafficUpdater()  		var tdiff = nt - tt;  		var diff = n - t;  		speed = diff / tdiff; -                if(!isNaN(speed)) +                if(!isNaN(speed)) {                          nmsMap.setSwitchColor(sw,colorFromSpeed(speed)); +			nmsMap.setSwitchInfo(sw,byteCount(speed*8,0)); +		}  	}  } @@ -208,7 +217,7 @@ function colorFromSpeed(speed,factor)  {  	var m = 1024 * 1024 / 8;  	if (factor == undefined) -		factor = 2; +		factor = 1.1;  	if (speed == 0)  		return blue;  	speed = speed < 0 ? 0 : speed; @@ -454,3 +463,29 @@ function snmpInit() {  	setLegend(5,green,"");  } +function cpuUpdater() { +	for (var sw in nmsData.switches.switches) { +		try { +			var cpu = 0; +			for (var u in nmsData.snmp.snmp[sw].misc.jnxOperatingCPU) { +				var local = nmsData.snmp.snmp[sw].misc['jnxOperatingCPU'][u]; +				cpu = Math.max(nmsData.snmp.snmp[sw].misc.jnxOperatingCPU[u],cpu); +			} +			nmsMap.setSwitchColor(sw, getColorStop(cpu * 10)); +			nmsMap.setSwitchInfo(sw, cpu + " % "); +		} catch (e) { +			nmsMap.setSwitchColor(sw, "white"); +			nmsMap.setSwitchInfo(sw, "N/A"); +		} +	} +} + +function cpuInit() { +	nmsData.addHandler("snmp", "mapHandler", cpuUpdater); +	drawGradient([green,orange,red]); +	setLegend(1,getColorStop(0),"0 %"); +	setLegend(2,getColorStop(250),"25 %"); +	setLegend(3,getColorStop(600),"60 %"); +	setLegend(4,getColorStop(1000),"100 %"); +	setLegend(5,"white","N/A"); +} diff --git a/web/nms-public.gathering.org/js/nms.js b/web/nms-public.gathering.org/js/nms.js index c09fca0..8783844 100644 --- a/web/nms-public.gathering.org/js/nms.js +++ b/web/nms-public.gathering.org/js/nms.js @@ -100,14 +100,16 @@ function nmsTimer(handler, interval, name, description) {   * Convenience function that doesn't support huge numbers, and it's easier   * to comment than to fix. But not really, but I'm not fixing it anyway.   */ -function byteCount(bytes) { +function byteCount(bytes,precision) { +	if (precision ==undefined) +		precision = 1;  	var units = ['', 'K', 'M', 'G', 'T', 'P'];  	var i = 0;  	while (bytes > 1024) {  		bytes = bytes / 1024;  		i++;  	} -	return bytes.toFixed(1) + units[i]; +	return bytes.toFixed(precision) + units[i];  }  /*  | 
