aboutsummaryrefslogtreecommitdiffstats
path: root/web/api/read
diff options
context:
space:
mode:
authorOle Mathias Aa. Heggem <msbone1995@gmail.com>2018-01-28 15:43:54 +0100
committerOle Mathias Aa. Heggem <msbone1995@gmail.com>2018-01-28 15:43:54 +0100
commit417d931bd1c961a7aa8f1569e949bbc2a7abfade (patch)
tree26fe991a502ea4c7966f906237d197180bc31fef /web/api/read
parent9866a8734360d54294ad96ad5149a44d676f1b83 (diff)
Making network first class citizen
Still work in progress
Diffstat (limited to 'web/api/read')
-rw-r--r--web/api/read/networks37
-rwxr-xr-xweb/api/read/switches-management4
2 files changed, 39 insertions, 2 deletions
diff --git a/web/api/read/networks b/web/api/read/networks
new file mode 100644
index 0000000..870ae8c
--- /dev/null
+++ b/web/api/read/networks
@@ -0,0 +1,37 @@
+#! /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;
+
+$nms::web::cc{'max-age'} = "5";
+$nms::web::cc{'stale-while-revalidate'} = "30";
+
+my $q2 = $nms::web::dbh->prepare('select network, name, vlan, tags, routing_point, placement, last_updated, subnet4, subnet6, gw4, gw6 from networks');
+
+$q2->execute();
+while (my $ref = $q2->fetchrow_hashref()) {
+ $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/;
+ my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4);
+ my $name = $ref->{'name'};
+ $nms::web::json{'networks'}{$ref->{'name'}}{'vlan'} = $ref->{'vlan'};
+ $nms::web::json{'networks'}{$ref->{'name'}}{'subnet4'} = $ref->{'subnet4'};
+ $nms::web::json{'networks'}{$ref->{'name'}}{'subnet6'} = $ref->{'subnet6'};
+ $nms::web::json{'networks'}{$ref->{'name'}}{'gw4'} = $ref->{'gw4'};
+ $nms::web::json{'networks'}{$ref->{'name'}}{'gw6'} = $ref->{'gw6'};
+ $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'x'} = $x2;
+ $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'y'} = $y2;
+ $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'width'} = $x1 - $x2;
+ $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'height'} = $y1 - $y2;
+ $nms::web::json{'networks'}{$ref->{'name'}}{'routing_point'} = $ref->{'routing_point'};
+ my $data = JSON::XS::decode_json($ref->{'tags'});
+ $nms::web::json{'networks'}{$ref->{'name'}}{'tags'} = $data;
+}
+
+finalize_output();
diff --git a/web/api/read/switches-management b/web/api/read/switches-management
index 9d8bc53..4b6cefa 100755
--- a/web/api/read/switches-management
+++ b/web/api/read/switches-management
@@ -20,9 +20,9 @@ $nms::web::cc{'max-age'} = "5";
$nms::web::cc{'stale-while-revalidate'} = "30";
if (!defined($switch)) {
- $q2 = $nms::web::dbh->prepare('select sysname,host(mgmt_v4_addr) as mgmt_v4_addr,subnet4,subnet6,host(mgmt_v6_addr) as mgmt_v6_addr,host(mgmt_v4_gw) as mgmt_v4_gw,host(mgmt_v6_gw) as mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null');
+ $q2 = $nms::web::dbh->prepare('select switches.sysname, host(switches.mgmt_v4_addr) as mgmt_v4_addr, host(switches.mgmt_v6_addr) as mgmt_v6_addr, switches.mgmt_vlan, switches.traffic_vlan, switches.poll_frequency, switches.last_updated, switches.distro_name, switches.distro_phy_port, switches.community, traffic_net.subnet4, traffic_net.subnet6, mgmt_net.gw4 as mgmt_v4_gw, mgmt_net.gw6 as mgmt_v6_gw from switches left join networks as traffic_net on (switches.traffic_vlan = traffic_net.name) left join networks as mgmt_net on (switches.mgmt_vlan = mgmt_net.name) where switches.placement is not null;');
} else {
- $q2 = $nms::web::dbh->prepare('select sysname,host(mgmt_v4_addr) as mgmt_v4_addr,subnet4,subnet6,host(mgmt_v6_addr) as mgmt_v6_addr,host(mgmt_v4_gw) as mgmt_v4_gw,host(mgmt_v6_gw) as mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null and sysname = ' . $nms::web::dbh->quote($switch) . ';');
+ $q2 = $nms::web::dbh->prepare('select sysname,host(mgmt_v4_addr) as mgmt_v4_addr,host(mgmt_v6_addr) as mgmt_v6_addr,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null and sysname = ' . $nms::web::dbh->quote($switch) . ';');
}
$q2->execute();