aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org/api
diff options
context:
space:
mode:
Diffstat (limited to 'web/nms.gathering.org/api')
-rw-r--r--web/nms.gathering.org/api/API.rst131
-rwxr-xr-xweb/nms.gathering.org/api/public/dhcp20
-rwxr-xr-xweb/nms.gathering.org/api/public/dhcp-summary16
-rwxr-xr-xweb/nms.gathering.org/api/public/location44
-rwxr-xr-xweb/nms.gathering.org/api/public/ping37
-rwxr-xr-xweb/nms.gathering.org/api/public/switch-state97
-rwxr-xr-xweb/nms.gathering.org/api/public/switches36
-rwxr-xr-xweb/nms.gathering.org/api/read/comments15
-rwxr-xr-xweb/nms.gathering.org/api/read/snmp30
-rwxr-xr-xweb/nms.gathering.org/api/read/switches-management30
-rwxr-xr-xweb/nms.gathering.org/api/write/comment-add24
-rwxr-xr-xweb/nms.gathering.org/api/write/comment-change25
-rwxr-xr-xweb/nms.gathering.org/api/write/switch-add92
-rwxr-xr-xweb/nms.gathering.org/api/write/switch-update123
14 files changed, 0 insertions, 720 deletions
diff --git a/web/nms.gathering.org/api/API.rst b/web/nms.gathering.org/api/API.rst
deleted file mode 100644
index 7d5c88b..0000000
--- a/web/nms.gathering.org/api/API.rst
+++ /dev/null
@@ -1,131 +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.
-
-Public
-......
-
-Use URL https://nms-public.tg16.gathering.org/api/public
-
-/api/public/dhcp
-----------------
-
-Methods: GET
-Update frequency: every second or so.
-
-Used to report time since last dhcp lease.
-
-/api/public/dhcp-summary
-------------------------
-
-Methods: GET
-Update frequency: every second or so.
-
-Used to report dhcp lease stats. Both recent stats, and total stats.
-
-/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.
-
-
-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.
diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp
deleted file mode 100755
index 7b048d1..0000000
--- a/web/nms.gathering.org/api/public/dhcp
+++ /dev/null
@@ -1,20 +0,0 @@
-#! /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'} = "10";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-finalize_output();
diff --git a/web/nms.gathering.org/api/public/dhcp-summary b/web/nms.gathering.org/api/public/dhcp-summary
deleted file mode 100755
index a0e5609..0000000
--- a/web/nms.gathering.org/api/public/dhcp-summary
+++ /dev/null
@@ -1,16 +0,0 @@
-#! /usr/bin/perl
-use lib '../../../../include';
-use strict;
-use warnings;
-use nms::web;
-
-nms::web::setwhen('2h');
-
-my $q2 = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp where $nms::web::when;");
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'dhcp'} = $ref;
-}
-$nms::web::cc{'max-age'} = "10";
-$nms::web::cc{'stale-while-revalidate'} = "15";
-finalize_output();
diff --git a/web/nms.gathering.org/api/public/location b/web/nms.gathering.org/api/public/location
deleted file mode 100755
index b940007..0000000
--- a/web/nms.gathering.org/api/public/location
+++ /dev/null
@@ -1,44 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '../../../../include';
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-#my $query = $nms::web::dbh->prepare("select * from switches where '185.110.150.7' << subnet4");
-my $query = $nms::web::dbh->prepare("select * from switches where ? << subnet4 or ? << subnet6");
-
-print "Cache-Control: max-age=0";
-print "Content-Type: text/html";
-print "\n\n";
-
-# get user ip from somewhere.
-# HTTP_X_FORWARDED_FOR is set by varnish. When using varnish, the REMOTE_ADDR will always be localhost.
-
-my @xff = split(",",$ENV{HTTP_X_FORWARDED_FOR});
-my $addr = $xff[0] // $ENV{REMOTE_ADDR};
-
-$query->execute($addr,$addr);
-
-# add start html: header + body etc.
-print "
-<html>
- <body style=\"text-align: center; font-size: 50pt;\">
-";
-
-# print address
-print "" . $addr ."<br \>";
-
-# print switch name and distroname.
-while ( my $ref = $query->fetchrow_hashref() ) {
- print $ref->{sysname}. " @ " . $ref->{distro};
- print "<br />";
-}
-
-# add end html
-print "
- </body>
-</html>
-";
diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping
deleted file mode 100755
index 811708d..0000000
--- a/web/nms.gathering.org/api/public/ping
+++ /dev/null
@@ -1,37 +0,0 @@
-#! /usr/bin/perl
-use lib '../../../../include';
-use strict;
-use warnings;
-use nms::web;
-
-nms::web::setwhen('15s');
-
-my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::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'};
- # Get seconds, without decimlas, from timestamp.
- # '00:01:01.435601' => 61 seconds.
- my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} );
- $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;");
-$qs->execute();
-while ( my $ref = $qs->fetchrow_hashref() ) {
- $nms::web::json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'};
-}
-
-my $lq = $nms::web::dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE "
- . $nms::web::when . " ORDER BY linknet, time DESC;");
-$lq->execute();
-while ( my $ref = $lq->fetchrow_hashref() ) {
- $nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ];
-}
-
-$nms::web::cc{'max-age'} = "1";
-$nms::web::cc{'stale-while-revalidate'} = "15";
-finalize_output();
diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state
deleted file mode 100755
index a6caea9..0000000
--- a/web/nms.gathering.org/api/public/switch-state
+++ /dev/null
@@ -1,97 +0,0 @@
-#! /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;
-
-my $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where '
- . $nms::web::when . 'group by switch);');
-
-$q->execute();
-while ( my $ref = $q->fetchrow_hashref() ) {
- my $sysname = $ref->{'sysname'};
-
- my %data = %{JSON::XS::decode_json($ref->{'data'})};
-
- for my $porti (keys %{$data{'ports'}}) {
- my %port = %{$data{'ports'}{$porti}};
- my $smallport = $porti;
- if ($porti =~ m/\.0$/) {
- next;
- }
- if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) {
- $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") {
- $json{'switches'}{$sysname}{'uplinks'}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1;
- }
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- $json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'switches'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{ifs}{$smallport}{'live'} += 1;
- $json{'switches'}{$sysname}{totals}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{totals}{'total'} += 1;
- }
- $json{'switches'}{$sysname}{'temp'} = $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'};
- $json{'switches'}{$sysname}{'time'} = $ref->{'time'};
-}
-
-nms::web::setwhen('15m','10m');
-my $q2 = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where '
- . $nms::web::when . 'group by switch);');
-
-$q2->execute();
-while ( my $ref = $q2->fetchrow_hashref() ) {
- my $sysname = $ref->{'sysname'};
-
- my %data = %{JSON::XS::decode_json($ref->{'data'})};
-
- for my $porti (keys %{$data{'ports'}}) {
- my %port = %{$data{'ports'}{$porti}};
- my $smallport = $porti;
- if ($porti =~ m/\.0$/) {
- next;
- }
- if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) {
- $smallport =~ s/[0-9-].*$//;
- } else {
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'};
- }
- if ($porti =~ /ge-0\/0\/4[4-7]$/) {
- $json{'then'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'then'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'then'}{$sysname}{'uplinks'}{'live'} += 1;
- }
- $json{'then'}{$sysname}{'uplinks'}{'total'} += 1;
- }
-
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- $json{'then'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'then'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'then'}{$sysname}{ifs}{$smallport}{'live'} += 1;
- $json{'then'}{$sysname}{totals}{'live'} += 1;
- }
- $json{'then'}{$sysname}{totals}{'total'} += 1;
- }
- $json{'then'}{$sysname}{'temp'} = $data{'misc'}{'enterprises.2636.3.1.13.1.7.7.1.0.0'}{''};
- $json{'then'}{$sysname}{'time'} = $ref->{'time'};
-}
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-finalize_output();
diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches
deleted file mode 100755
index 890b7d7..0000000
--- a/web/nms.gathering.org/api/public/switches
+++ /dev/null
@@ -1,36 +0,0 @@
-#! /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,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,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()) {
- $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/;
- my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4);
- my $sysname = $ref->{'sysname'};
- $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;
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'distro_name'} = $ref->{'distro_name'};
-}
-
-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()) {
- $nms::web::json{'linknets'}{$ref->{'linknet'}} = $ref;
-}
-
-finalize_output();
diff --git a/web/nms.gathering.org/api/read/comments b/web/nms.gathering.org/api/read/comments
deleted file mode 100755
index 4adfb2b..0000000
--- a/web/nms.gathering.org/api/read/comments
+++ /dev/null
@@ -1,15 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '../../../../include';
-use nms::web;
-use strict;
-use warnings;
-
-my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc');
-$query->execute();
-while (my $ref = $query->fetchrow_hashref()) {
- push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref;
-}
-
-nms::web::finalize_output();
diff --git a/web/nms.gathering.org/api/read/snmp b/web/nms.gathering.org/api/read/snmp
deleted file mode 100755
index f69ca62..0000000
--- a/web/nms.gathering.org/api/read/snmp
+++ /dev/null
@@ -1,30 +0,0 @@
-#! /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 JSON;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "10";
-
-my $q = $nms::web::dbh->prepare('select sysname,data from snmp natural join switches where id in (select max(id) from snmp where '
- . $nms::web::when . 'group by switch);');
-
-$q->execute();
-while (my $ref = $q->fetchrow_hashref()) {
- my $sysname = $ref->{'sysname'};
-
- # This is, strictly speaking, redundant. But by doing this, we can
- # re-use the standard methods of finalize_output() and whatnot.
- my $data = JSON::XS::decode_json($ref->{'data'});
-
- $nms::web::json{'snmp'}{$ref->{'sysname'}} = $data;
-}
-
-finalize_output();
diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management
deleted file mode 100755
index 4461a90..0000000
--- a/web/nms.gathering.org/api/read/switches-management
+++ /dev/null
@@ -1,30 +0,0 @@
-#! /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,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,distro_phy_port from switches where placement is not null');
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- my $sysname = $ref->{'sysname'};
- $nms::web::json{'switches'}{$ref->{'sysname'}} = $ref;
-}
-
-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/write/comment-add b/web/nms.gathering.org/api/write/comment-add
deleted file mode 100755
index bcea6dc..0000000
--- a/web/nms.gathering.org/api/write/comment-add
+++ /dev/null
@@ -1,24 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-use lib '../../../../include';
-use utf8;
-use nms::web qw($dbh db_safe_quote get_input finalize_output);
-use strict;
-use warnings;
-
-my $in = get_input();
-my %tmp = %{JSON::XS::decode_json($in)};
-
-my $data = $dbh->quote($tmp{'comment'});
-my $switch = $dbh->quote($tmp{'switch'});
-my $user = $dbh->quote($ENV{'REMOTE_USER'} || "undefined");
-
-my $q = $nms::web::dbh->prepare("INSERT INTO switch_comments (time,username,switch,comment) values (now(),$user,(select switch from switches where sysname = $switch limit 1),$data)");
-$q->execute();
-
-$nms::web::cc{'max-age'} = '0';
-$nms::web::cc{'stale-while-revalidate'} = '0';
-$nms::web::json{'state'} = 'ok';
-
-print "X-ban: /api/read/comments\n";
-finalize_output();
diff --git a/web/nms.gathering.org/api/write/comment-change b/web/nms.gathering.org/api/write/comment-change
deleted file mode 100755
index 0bdabc0..0000000
--- a/web/nms.gathering.org/api/write/comment-change
+++ /dev/null
@@ -1,25 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-use lib '../../../../include';
-use utf8;
-use nms;
-use nms::web qw($dbh db_safe_quote get_input finalize_output);
-
-use strict;
-use warnings;
-
-my $in = get_input();
-my %tmp = %{JSON::XS::decode_json($in)};
-
-my $id = $dbh->quote($tmp{'comment'});
-my $state = $dbh->quote($tmp{'state'});
-
-my $q = $nms::web::dbh->prepare("UPDATE switch_comments SET state = " . $state . " WHERE id = " . $id . ";");
-$q->execute();
-
-$nms::web::cc{'max-age'} = '0';
-$nms::web::cc{'stale-while-revalidate'} = '0';
-$nms::web::json{'state'} = 'ok';
-
-print "X-ban: /api/read/comments\n";
-finalize_output();
diff --git a/web/nms.gathering.org/api/write/switch-add b/web/nms.gathering.org/api/write/switch-add
deleted file mode 100755
index 0051111..0000000
--- a/web/nms.gathering.org/api/write/switch-add
+++ /dev/null
@@ -1,92 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-#use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '../../../../include';
-use nms;
-use nms::web qw(%get_params %json finalize_output get_input $dbh);
-use nms::util qw(guess_placement);
-use strict;
-use warnings;
-use JSON;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "0";
-
-my $in = get_input();
-my @tmp = @{JSON::XS::decode_json($in)};
-
-my @added;
-my @dups;
-
-my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-
-my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan');
-
-sub convertplace
-{
- my %in = %{$_[0]};
- my %out = ();
-
- if (not defined $in{'x1'} and defined($in{'x'})) {
- $out{'x1'} = int($in{'x'});
- $out{'y1'} = int($in{'y'});
- $out{'xx'} = int($in{'x'} + $in{'width'});
- $out{'yy'} = int($in{'y'} + $in{'height'});
- } else {
- return \%in;
- }
- return \%out;
-}
-
-foreach my $tmp2 (@tmp) {
- my %switch = %{$tmp2};
- my $affected = 0;
- my %template = ();
- map { $template{$_} = 'DEFAULT' } @fields;
- if (not defined($switch{'sysname'})) {
- next;
- }
-
- $sth->execute( $switch{'sysname'});
- while ( my @row = $sth->fetchrow_array ) {
- $affected += 1;
- }
-
- if ($affected == 0) {
- my %placement;
- if (not defined ($switch{'placement'})) {
- %placement = guess_placement($switch{'sysname'});
- } else {
- %placement = %{convertplace($switch{'placement'})};
- }
- if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) {
- $switch{'ip'} = $switch{'mgtmt4'};
- }
- if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) {
- $switch{'secondary_ip'} = $switch{'mgtmt6'};
- }
- my ($x1,$x2,$y1,$y2);
- $x1 = $placement{'x1'};
- $y1 = $placement{'y1'};
- $x2 = $placement{'xx'};
- $y2 = $placement{'yy'};
- $switch{'placement'} = "(($x1,$y1),($x2,$y2))";
-
- map {
- if (defined ($template{$_})) {
- $template{$_} = $dbh->quote($switch{$_});
- }
- } keys %switch;
-
-
- $nms::web::dbh->do("INSERT INTO SWITCHES (mgmt_v4_addr, sysname, poll_frequency, community, lldp_chassis_id, mgmt_v6_addr, placement,subnet4,subnet6,distro_name) VALUES ($template{'mgmt_v4_addr'}, $template{'sysname'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'mgmt_v6_addr'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro_name'});");
- push @added, $switch{'sysname'};
- }
-}
-
-$json{'switches_addded'} = \@added;
-
-print "X-ban: /api/.*switches.*\n";
-finalize_output();
diff --git a/web/nms.gathering.org/api/write/switch-update b/web/nms.gathering.org/api/write/switch-update
deleted file mode 100755
index 14c8773..0000000
--- a/web/nms.gathering.org/api/write/switch-update
+++ /dev/null
@@ -1,123 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-#use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '../../../../include';
-use nms;
-use nms::web qw(%get_params %json finalize_output get_input $dbh);
-use nms::util qw(guess_placement);
-use strict;
-use warnings;
-use JSON;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "0";
-
-my $in = get_input();
-my @tmp = @{JSON::XS::decode_json($in)};
-
-my @added;
-my @dups;
-
-my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-
-
-my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan');
-
-sub convertplace
-{
- my %in = %{$_[0]};
- my %out = ();
-
- if (not defined $in{'x1'} and defined($in{'x'})) {
- $out{'x1'} = int($in{'x'});
- $out{'y1'} = int($in{'y'});
- $out{'xx'} = int($in{'x'} + $in{'width'});
- $out{'yy'} = int($in{'y'} + $in{'height'});
- } else {
- return \%in;
- }
- return \%out;
-}
-
-foreach my $tmp2 (@tmp) {
- my %switch = %{$tmp2};
- my $affected = 0;
- my %template = ();
- map { $template{$_} = 'DEFAULT' } @fields;
- if (not defined($switch{'sysname'})) {
- next;
- }
-
- $sth->execute( $switch{'sysname'});
- while ( my @row = $sth->fetchrow_array ) {
- $affected += 1;
- }
-
- if ($affected == 0) {
- my %placement;
- if (not defined ($switch{'placement'})) {
- %placement = guess_placement($switch{'sysname'});
- } else {
- %placement = %{convertplace($switch{'placement'})};
- }
- if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) {
- $switch{'ip'} = $switch{'mgtmt4'};
- }
- if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) {
- $switch{'secondary_ip'} = $switch{'mgtmt6'};
- }
- my ($x1,$x2,$y1,$y2);
- $x1 = $placement{'x1'};
- $y1 = $placement{'y1'};
- $x2 = $placement{'xx'};
- $y2 = $placement{'yy'};
- $switch{'placement'} = "(($x1,$y1),($x2,$y2))";
-
- map {
- if (defined ($template{$_})) {
- $template{$_} = $dbh->quote($switch{$_});
- }
- } keys %switch;
-
-
- $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});");
- push @added, $switch{'sysname'};
- } else {
- if (defined($switch{'placement'})) {
- my %placement;
- if ($switch{'placement'} eq "reset") {
- %placement = guess_placement($switch{'sysname'});
- } else {
- %placement = %{convertplace($switch{'placement'})};
- }
- my ($x1,$x2,$y1,$y2);
- $x1 = $placement{'x1'};
- $y1 = $placement{'y1'};
- $x2 = $placement{'xx'};
- $y2 = $placement{'yy'};
- $switch{'placement'} = "(($x1,$y1),($x2,$y2))";
- push @dups, "not really, but: " . $switch{'placement'};
- }
- if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) {
- $switch{'ip'} = $switch{'mgtmt4'};
- }
- if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) {
- $switch{'secondary_ip'} = $switch{'mgtmt6'};
- }
- my @set;
- map {
- if (defined($template{$_})) {
- push @set, "$_=" . $dbh->quote($switch{$_});
- }
- } keys %switch;
- $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";");
- push @dups, $switch{'sysname'};
- }
-}
-$json{'switches_addded'} = \@added;
-$json{'switches_updated'} = \@dups;
-
-print "X-ban: /api/.*switches.*\n";
-finalize_output();