aboutsummaryrefslogtreecommitdiffstats
path: root/web/api/public
diff options
context:
space:
mode:
authorOle Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com>2018-03-17 18:03:23 +0100
committerOle Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com>2018-03-17 18:03:23 +0100
commitdc97b997e8d6e5edc63c598c05090a8b98e79757 (patch)
tree42762b3582ec8416cc70527c178dda6498b90f19 /web/api/public
parent8607a0880724eca35c220f7c26a138d9f0f50f72 (diff)
Added support for delete switches
Diffstat (limited to 'web/api/public')
-rwxr-xr-xweb/api/public/dhcp4
-rwxr-xr-xweb/api/public/distro-tree2
-rwxr-xr-xweb/api/public/location2
-rwxr-xr-xweb/api/public/switch-state9
-rwxr-xr-xweb/api/public/switches2
5 files changed, 10 insertions, 9 deletions
diff --git a/web/api/public/dhcp b/web/api/public/dhcp
index 88f1eb5..0b0bb49 100755
--- a/web/api/public/dhcp
+++ b/web/api/public/dhcp
@@ -8,13 +8,13 @@ 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;');
+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 . ' and switches.deleted = false order by sysname,time desc;');
$q->execute();
while ( my $ref = $q->fetchrow_hashref() ) {
my $sysname = $ref->{'sysname'};
$json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'};
}
-my $q2 = $nms::web::dbh->prepare("select sysname,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join switches where $nms::web::when group by switches.sysname;");
+my $q2 = $nms::web::dbh->prepare("select sysname,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join switches where $nms::web::when and switches.deleted = false group by switches.sysname;");
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
$nms::web::json{'switches'}{$ref->{sysname}} = $ref;
diff --git a/web/api/public/distro-tree b/web/api/public/distro-tree
index 5d93e1b..cff35ec 100755
--- a/web/api/public/distro-tree
+++ b/web/api/public/distro-tree
@@ -12,7 +12,7 @@ use Data::Dumper;
$nms::web::cc{'max-age'} = "20";
-my $q2 = $nms::web::dbh->prepare('select sysname,distro_phy_port,distro_name from switches where placement is not null and distro_name is not null and distro_phy_port is not null');
+my $q2 = $nms::web::dbh->prepare('select sysname,distro_phy_port,distro_name from switches where placement is not null and distro_name is not null and distro_phy_port is not null and deleted = false');
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
diff --git a/web/api/public/location b/web/api/public/location
index 2247f73..b960bb2 100755
--- a/web/api/public/location
+++ b/web/api/public/location
@@ -8,7 +8,7 @@ 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");
+my $query = $nms::web::dbh->prepare("select * from switches where deleted = false and (? << subnet4 or ? << subnet6)");
print "Cache-Control: max-age=0";
print "Content-Type: text/html";
diff --git a/web/api/public/switch-state b/web/api/public/switch-state
index 77350c7..965e881 100755
--- a/web/api/public/switch-state
+++ b/web/api/public/switch-state
@@ -14,9 +14,9 @@ my ($switch, $port) = split(/\//,$target,2);
my $q;
if (!defined($switch)) {
- $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 = $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 . ' and switches.deleted = false group by switch);');
} else {
- $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) and sysname = ' . $nms::web::dbh->quote($switch) . ';');
+ $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) and sysname = ' . $nms::web::dbh->quote($switch) . ' and switches.deleted = false;');
}
$q->execute();
@@ -24,7 +24,7 @@ while ( my $ref = $q->fetchrow_hashref() ) {
my $sysname = $ref->{'sysname'};
my %data = %{JSON::XS::decode_json($ref->{'data'})};
-
+
$json{'switches'}{$sysname}{'clients'}{'live'} = 0;
$json{'then'}{$sysname}{'clients'}{'live'} = 0;
for my $porti (keys %{$data{'ports'}}) {
@@ -93,7 +93,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) {
my $sysname = $ref->{'sysname'};
my %data = %{JSON::XS::decode_json($ref->{'data'})};
-
+
for my $porti (keys %{$data{'ports'}}) {
if (defined($port) and $port ne "" and $port ne $porti) {
next;
@@ -149,3 +149,4 @@ while ( my $ref = $q2->fetchrow_hashref() ) {
$nms::web::cc{'max-age'} = "5";
$nms::web::cc{'stale-while-revalidate'} = "30";
finalize_output();
+
diff --git a/web/api/public/switches b/web/api/public/switches
index e7f4cb0..44fde3c 100755
--- a/web/api/public/switches
+++ b/web/api/public/switches
@@ -13,7 +13,7 @@ use Data::Dumper;
$nms::web::cc{'max-age'} = "5";
$nms::web::cc{'stale-while-revalidate'} = "30";
-my $q2 = $nms::web::dbh->prepare('select switch,sysname,tags,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,community,last_updated from switches where placement is not null');
+my $q2 = $nms::web::dbh->prepare('select switch,sysname,tags,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,community,last_updated from switches where placement is not null and deleted = false');
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {