diff options
| -rw-r--r-- | web/nms.gathering.org/api/API.rst | 49 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/private/switches-management | 34 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/public/switches | 13 | 
3 files changed, 65 insertions, 31 deletions
diff --git a/web/nms.gathering.org/api/API.rst b/web/nms.gathering.org/api/API.rst index b56db64..5876302 100644 --- a/web/nms.gathering.org/api/API.rst +++ b/web/nms.gathering.org/api/API.rst @@ -3,10 +3,13 @@ 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 /switch-state.pl?now=2015-04-02T15:00:00 +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. @@ -16,40 +19,40 @@ 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. -comment-add.pl --------------- +/appi/private/comment-add +-------------------------  Methods: POST   -- Add a comment -comment-change.pl ------------------ +/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. -comment.pl -- View comments ---------------------------- +/api/private/comments +---------------------  Methods: GET  Update frequency: on user input -ping.pl -- Being phased out ---------------------------- +/api/public/ping +----------------  Methods: GET  Update frequency: every second or so. -Used to report switch latency and linknet latency. +Used to report linknet latency.  The switch latency is being integrated into switch-state.pl and linknet  latency will similarly be moved. -port-state.pl -- Get per-port statistics ----------------------------------------- +/api/private/port-state +-----------------------  Methods: GET  Update frequency: Every few seconds, based on SNMP data. @@ -59,8 +62,8 @@ Private.  Returns detailed per-port statistics. Being somewhat reorganized but will  remain highly relevant. -switches_add.pl -- Add a switch -------------------------------- +/api/private/switch-add +-----------------------  Methods: POST @@ -68,18 +71,26 @@ Add switches, supports same format as tools/add_switches.txt.pl  Accepts an array of switches. -switches.pl ------------ +/api/public/switches +--------------------  Methods: GET  Update frequency: Infrequent (on topology/config changes) -List all switches and map positions. Output is filtered for public users. +List all switches and map positions.  Used to draw switches on a map and provide static information. -switch-state.pl -- List state for switches ------------------------------------------- +/api/public/switches-management +------------------------------- + +Methods: GET +Update frequency: Infrequent (on topology/config changes) + +List management information for switches. + +/api/public/switch-state +------------------------  Methods: GET  Update frequency: Every second diff --git a/web/nms.gathering.org/api/private/switches-management b/web/nms.gathering.org/api/private/switches-management new file mode 100755 index 0000000..f007ad6 --- /dev/null +++ b/web/nms.gathering.org/api/private/switches-management @@ -0,0 +1,34 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web; +use strict; +use warnings; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "60"; + +my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,switchtype,poll_frequency,community,last_updated from switches natural join placements'); + +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { +	my $sysname = $ref->{'sysname'}; +	$nms::web::json{'switches'}{$ref->{'sysname'}}{'switchtype'} = $ref->{'switchtype'}; +	$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'ip'} = $ref->{'ip'}; +	$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'poll_frequency'} = $ref->{'poll_frequency'}; +	$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'community'} = $ref->{'community'}; +	$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'last_updated'} = $ref->{'last_updated'}; +} + +my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, addr1, (select sysname from switches where switch = switch2) as sysname2,addr2 from linknets'); + +$q4->execute(); +while (my $ref = $q4->fetchrow_hashref()) { +	$nms::web::json{'linknets'}{$ref->{'linknet'}} = $ref; +} + +finalize_output(); diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 4df81f2..8cf8740 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/api/public/switches @@ -20,24 +20,13 @@ while (my $ref = $q2->fetchrow_hashref()) {  	my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4);  	my $sysname = $ref->{'sysname'};  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'switchtype'} = $ref->{'switchtype'}; -	if (!(nms::web::ispublic())) { -		$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'ip'} = $ref->{'ip'}; -		$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'poll_frequency'} = $ref->{'poll_frequency'}; -		$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'community'} = $ref->{'community'}; -		$nms::web::json{'switches'}{$ref->{'sysname'}}{'management'}{'last_updated'} = $ref->{'last_updated'}; -	}  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'x'} = $x2;  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'y'} = $y2;  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2;  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'height'} = $y1 - $y2;  } -my $q4; -if (!(nms::web::ispublic())) { -	$q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, addr1, (select sysname from switches where switch = switch2) as sysname2,addr2 from linknets'); -} else { -	$q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, (select sysname from switches where switch = switch2) as sysname2 from linknets'); -} +my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, (select sysname from switches where switch = switch2) as sysname2 from linknets');  $q4->execute();  while (my $ref = $q4->fetchrow_hashref()) {  | 
