diff options
Diffstat (limited to 'web')
| -rw-r--r-- | web/nms-public.gathering.org/api/API.rst | 113 | ||||
| -rwxr-xr-x | web/nms-public.gathering.org/api/public/dhcp | 20 | ||||
| -rwxr-xr-x | web/nms-public.gathering.org/api/public/switch-state | 8 | ||||
| -rwxr-xr-x | web/nms-public.gathering.org/api/public/switches | 2 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-map.js | 38 | 
5 files changed, 65 insertions, 116 deletions
| diff --git a/web/nms-public.gathering.org/api/API.rst b/web/nms-public.gathering.org/api/API.rst deleted file mode 100644 index 61fbb5a..0000000 --- a/web/nms-public.gathering.org/api/API.rst +++ /dev/null @@ -1,113 +0,0 @@ -API-dok -======= - -Work in progress. - -There are two relevant paths: /api/public and /api/private. One requires -user-login in, the other does not. - -General: All end-points that output time-based data accept the "now=<time>" -argument, where, <time> is YYYY-MM-DDThh:mm:ss. E.g: - -GET /api/public/switch-state?now=2015-04-02T15:00:00 - -There is no guarantee that the data is exact time-wise, thus each endpoint -should also output relevant time stamps. - -Currently error handling sucks. - -This document is in no way complete, but it's a start. It will be updated -as time permits and API's stabilize. - -Private -....... - -/api/private/comment-add ------------------------- - -Methods: POST - -Add a comment - -/api/private/comment-change ---------------------------- - -Methods: POST - -Note that comments are never really deleted, but the state can be set to -deleted, making sure they are never shown. - -/api/private/comments ---------------------- - -Methods: GET - -Update frequency: on user input - -Lists comments. - -/api/private/snmp ------------------ - -Methods: GET - -Update frequency: Every few seconds, based on SNMP data. - -Returns full SNMP-data, split into two trees. 'misc' and 'ports'. - - -/api/private/switches-management --------------------------------- - -Methods: GET - -Update frequency: Infrequent (on topology/config changes) - -List management information for switches. - -/api/private/switch-add ------------------------ - -Methods: POST - -Add or update switches, supports same format as tools/add_switches.txt.pl - -Accepts an array of switches. - -Magic: If you set placement to be "reset", it will re-calculate placement -based on sysname. For new switches, this is redundant as an empty -placement-field will trigger the same behavior. - - -Public -...... - -/api/public/ping ----------------- - -Methods: GET -Update frequency: every second or so. - -Used to report linknet latency. - -The switch latency is being integrated into switch-state.pl and linknet -latency will similarly be moved. - -/api/public/switches --------------------- - -Methods: GET -Update frequency: Infrequent (on topology/config changes) - -List all switches and map positions. - -Used to draw switches on a map and provide static information. - -/api/public/switch-state ------------------------- - -Methods: GET -Update frequency: Every second - -Provides state for each switch, including total port speed, uplink port -speed, latency and temperature. diff --git a/web/nms-public.gathering.org/api/public/dhcp b/web/nms-public.gathering.org/api/public/dhcp new file mode 100755 index 0000000..91d52af --- /dev/null +++ b/web/nms-public.gathering.org/api/public/dhcp @@ -0,0 +1,20 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web qw (%json finalize_output); +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() ) { +	my $sysname = $ref->{'sysname'}; +	$json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'}; +} + +$nms::web::cc{'max-age'} = "5"; +$nms::web::cc{'stale-while-revalidate'} = "30"; +finalize_output(); diff --git a/web/nms-public.gathering.org/api/public/switch-state b/web/nms-public.gathering.org/api/public/switch-state index 6f7573c..7fa6ff5 100755 --- a/web/nms-public.gathering.org/api/public/switch-state +++ b/web/nms-public.gathering.org/api/public/switch-state @@ -19,8 +19,12 @@ while ( my $ref = $q->fetchrow_hashref() ) {  	for my $porti (keys %{$data{'ports'}}) {  		my %port = %{$data{'ports'}{$porti}};  		my $smallport = $porti; -		$smallport =~ s/[0-9-].*$//; -		if ($porti =~  /ge-0\/0\/4[4-7]/) { +		if (not $smallport =~ m/^ae/) { +			$smallport =~ s/[0-9-].*$//; +		} else { +			$json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; +		} +		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-public.gathering.org/api/public/switches b/web/nms-public.gathering.org/api/public/switches index 7e7f10b..3aa8af8 100755 --- a/web/nms-public.gathering.org/api/public/switches +++ b/web/nms-public.gathering.org/api/public/switches @@ -12,7 +12,7 @@ use Data::Dumper;  $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,poll_frequency,community,last_updated from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null');  $q2->execute();  while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index d595c4a..1f4d6b7 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -47,6 +47,7 @@ var nmsMap = nmsMap || {  	},  	_color: { }, +	_linknets: {} ,  	_highlight: { },  	_highlightActive: false,  	_c: {} @@ -157,6 +158,7 @@ nmsMap._resizeEvent = function() {  		nmsMap._blurDrawn = false;  		nmsMap._drawBG();  		nmsMap._drawAllSwitches(); +		nmsMap._drawAllLinknets();  		nmsMap.drawNow();  		nmsMap.stats.resizeEvents++;  	} @@ -327,6 +329,40 @@ nmsMap._drawText = function(ctx, text, box, align) {  	ctx.restore();  }; +nmsMap._setLinknetColor = function(l, color1, color2) +{ +	var oldcolor1; +	var oldcolor2; +	try { +		oldcolor1 = nmsMap._linknets[l].sysname1; +		oldcolor2 = nmsMap._linknets[l].sysname2; +		if (oldcolor1 == color1 && oldcolor2 == color2) { +			return ; +		} +	} catch (e) {} +	nmsMap._linknets[l] = {}; +	nmsMap._linknets[l].sysname1 = color1; +	nmsMap._linknets[l].sysname2 = color2; +	nmsMap._drawLinknet(l) +} + +nmsMap._drawLinknet = function(l) { +	try { +		var color1 = blue; +		var color2 = blue; +		try { +			color1 = nmsMap._linknets[l].sysname1; +			color2 = nmsMap._linknets[l].sysname2; +		} catch(e) { } +		nmsMap._connectSwitches(nmsData.switches.linknets[l].sysname1, nmsData.switches.linknets[l].sysname2, color1, color2); +	} catch(e) { } +} + +nmsMap._drawAllLinknets = function() { +	for (var l in nmsData.switches.linknets) { +		nmsMap._drawLinknet(l); +	} +}  nmsMap._drawAllSwitches = function() {  	if (nmsData.switches == undefined) {  		this.stats.earlyDrawAll++; @@ -383,10 +419,12 @@ nmsMap._connectBoxes = function(box1, box2,color1, color2) {  	gradient.addColorStop(0, color1);  	gradient.addColorStop(1, color2);  	ctx.strokeStyle = gradient; +	ctx.beginPath();  	ctx.moveTo(x0,y0);  	ctx.lineTo(x1,y1);   	ctx.lineWidth = 5;  	ctx.stroke(); +	ctx.closePath();  	ctx.restore();  }; | 
