aboutsummaryrefslogtreecommitdiffstats
path: root/web/api
diff options
context:
space:
mode:
authorLasse Haugen <haugen.lasse@gmail.com>2017-03-31 22:22:08 +0200
committerLasse Haugen <haugen.lasse@gmail.com>2017-03-31 22:22:08 +0200
commit134299c3d95a10ed11b184eac61a704c45d17000 (patch)
tree607d9dd8530b86c9e112a3ed11a74e52f80fa373 /web/api
parent108377f8adf91d34481ff344cb914e0c6101e530 (diff)
switches.txt as an api endpoint
Diffstat (limited to 'web/api')
-rwxr-xr-xweb/api/read/distro-management31
1 files changed, 31 insertions, 0 deletions
diff --git a/web/api/read/distro-management b/web/api/read/distro-management
new file mode 100755
index 0000000..2aa3273
--- /dev/null
+++ b/web/api/read/distro-management
@@ -0,0 +1,31 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+use CGI qw(fatalsToBrowser);
+use DBI;
+use lib '/opt/gondul/include';
+use nms;
+use nms::web;
+use strict;
+use warnings;
+use Data::Dumper;
+
+my $target = $ENV{REQUEST_URI};
+$target =~ s/$ENV{SCRIPT_NAME}//;
+$target =~ s/^\///;
+my ($switch, $port) = split(/\//,$target,2);
+my $q2;
+
+$nms::web::cc{'max-age'} = "5";
+$nms::web::cc{'stale-while-revalidate'} = "30";
+
+$q2 = $nms::web::dbh->prepare('SELECT distro_name,sysname,subnet4,subnet6,traffic_vlan,distro_phy_port FROM switches WHERE placement is not null AND distro_name is not null AND distro_phy_port is not null');
+
+$q2->execute();
+while (my $ref = $q2->fetchrow_hashref()) {
+ my $sysname = $ref->{'sysname'};
+ my $distro = $ref->{'distro_name'};
+ $nms::web::json{'distros'}{$distro}{$sysname} = $ref;
+}
+
+finalize_output();