aboutsummaryrefslogtreecommitdiffstats
path: root/web/api/read
diff options
context:
space:
mode:
authorroot <root@colazero.tele.tg18.gathering.org>2018-03-21 14:13:32 +0100
committerroot <root@colazero.tele.tg18.gathering.org>2018-03-21 14:13:32 +0100
commit05e09f3b63269a48d1beb0dc9900b180101cec7f (patch)
treeb96dbc2cc53a79968e4c60a7b3a729ea4d937299 /web/api/read
parentc6d676b8d07dcd081626ad86849900977327bbb7 (diff)
parent8bee35e8be72510d8bdc7ed5de49a8d031e829a5 (diff)
Merge branch 'master' of github.com:tech-server/gondul
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 9182b60..77badf4 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 and deleted = false');
+ $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 and switches.deleted = false;');
} 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 deleted = false 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) . ' and switches.deleted = false;');
}
$q2->execute();