aboutsummaryrefslogtreecommitdiffstats
path: root/web/api
diff options
context:
space:
mode:
Diffstat (limited to 'web/api')
-rwxr-xr-xweb/api/public/dhcp10
-rwxr-xr-xweb/api/public/ping4
-rwxr-xr-xweb/api/public/switch-state28
-rwxr-xr-xweb/api/read/distro-management2
-rwxr-xr-x[-rw-r--r--]web/api/read/networks0
-rwxr-xr-xweb/api/read/switches-management10
-rwxr-xr-xweb/api/read/template-list21
-rwxr-xr-x[-rw-r--r--]web/api/write/network-add0
-rwxr-xr-x[-rw-r--r--]web/api/write/network-update57
-rwxr-xr-xweb/api/write/switch-update2
10 files changed, 60 insertions, 74 deletions
diff --git a/web/api/public/dhcp b/web/api/public/dhcp
index 0b0bb49..f153a49 100755
--- a/web/api/public/dhcp
+++ b/web/api/public/dhcp
@@ -8,16 +8,16 @@ 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 . ' and switches.deleted = false order by sysname,time desc;');
+my $q = $nms::web::dbh->prepare('select distinct on (name) extract(epoch from date_trunc(\'second\',time)) as time,name from dhcp join networks on dhcp.network = networks.network where ' . $nms::web::when . ' order by name,time desc;');
$q->execute();
while ( my $ref = $q->fetchrow_hashref() ) {
- my $sysname = $ref->{'sysname'};
- $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'};
+ my $sysname = $ref->{'sname'};
+ $json{'dhcp'}{$ref->{'name'}} = $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 and switches.deleted = false group by switches.sysname;");
+my $q2 = $nms::web::dbh->prepare("select name,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join networks where $nms::web::when group by networks.name;");
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'switches'}{$ref->{sysname}} = $ref;
+ $nms::web::json{'networks'}{$ref->{name}} = $ref;
}
$nms::web::cc{'max-age'} = "10";
diff --git a/web/api/public/ping b/web/api/public/ping
index 1928368..be37875 100755
--- a/web/api/public/ping
+++ b/web/api/public/ping
@@ -4,7 +4,7 @@ use strict;
use warnings;
use nms::web;
-nms::web::setwhen('15s');
+nms::web::setwhen('25s');
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)");
@@ -37,5 +37,5 @@ while ( my $ref = $lq->fetchrow_hashref() ) {
}
$nms::web::cc{'max-age'} = "1";
-$nms::web::cc{'stale-while-revalidate'} = "15";
+$nms::web::cc{'stale-while-revalidate'} = "5";
finalize_output();
diff --git a/web/api/public/switch-state b/web/api/public/switch-state
index 965e881..528bf7d 100755
--- a/web/api/public/switch-state
+++ b/web/api/public/switch-state
@@ -7,17 +7,19 @@ 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 $target = $ENV{REQUEST_URI};
+#$target =~ s/$ENV{SCRIPT_NAME}//;
+#$target =~ s/^\///;
+#my ($switch, $port) = split(/\//,$target,2);
+my $port;
+my $switch;
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 . ' 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) . ' and switches.deleted = false;');
-}
+#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) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];');
+#} 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->execute();
while ( my $ref = $q->fetchrow_hashref() ) {
@@ -42,7 +44,7 @@ while ( my $ref = $q->fetchrow_hashref() ) {
$json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'};
}
if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/i) {
+ $data{'ports'}{$porti}{'ifAlias'} =~ m/Fysisk/i) {
if ($port{'ifAdminStatus'} eq "up") {
$json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
$json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
@@ -83,9 +85,9 @@ while ( my $ref = $q->fetchrow_hashref() ) {
nms::web::setwhen('15m','10m');
my $q2;
if (!defined($switch)) {
- $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 = $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 switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];');
} else {
- $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) and sysname = ' . $nms::web::dbh->quote($switch) . ';');
+ $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) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'] and sysname = ' . $nms::web::dbh->quote($switch) . ';');
}
$q2->execute();
@@ -109,7 +111,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) {
$json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'};
}
if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/i) {
+ $data{'ports'}{$porti}{'ifAlias'} =~ m/Fysisk/i) {
if ($port{'ifAdminStatus'} eq "up") {
$json{'then'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
$json{'then'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
diff --git a/web/api/read/distro-management b/web/api/read/distro-management
index 7fbebef..55ca07e 100755
--- a/web/api/read/distro-management
+++ b/web/api/read/distro-management
@@ -19,7 +19,7 @@ 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 and deleted = false');
+$q2 = $nms::web::dbh->prepare('SELECT distro_name,sysname,distro_phy_port 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/read/networks b/web/api/read/networks
index 870ae8c..870ae8c 100644..100755
--- a/web/api/read/networks
+++ b/web/api/read/networks
diff --git a/web/api/read/switches-management b/web/api/read/switches-management
index 77badf4..b42c84b 100755
--- a/web/api/read/switches-management
+++ b/web/api/read/switches-management
@@ -13,14 +13,20 @@ use Data::Dumper;
my $target = $ENV{REQUEST_URI};
$target =~ s/$ENV{SCRIPT_NAME}//;
$target =~ s/^\///;
-my ($switch, $port) = split(/\//,$target,2);
+my $switch;
+my $port;
+
+if ($target !~ m/now=/) {
+ ($switch, $port) = split(/\//,$target,2);
+}
+
my $q2;
$nms::web::cc{'max-age'} = "5";
$nms::web::cc{'stale-while-revalidate'} = "30";
if (!defined($switch)) {
- $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;');
+ $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, host(mgmt_net.gw4) as mgmt_v4_gw, host(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,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;');
}
diff --git a/web/api/read/template-list b/web/api/read/template-list
new file mode 100755
index 0000000..d1c8773
--- /dev/null
+++ b/web/api/read/template-list
@@ -0,0 +1,21 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+use lib '/opt/gondul/include';
+use nms::web;
+use strict;
+use warnings;
+
+my $template_dir = "/opt/gondul/web/templates";
+
+opendir (DIR, $template_dir) or die $!;
+
+while (my $file = readdir(DIR)) {
+ next if ($file =~ m/^\./);
+ my %meh;
+ $meh{'file'} = $file;
+
+ push @{$nms::web::json{'templates'}},\%meh;
+}
+
+nms::web::finalize_output();
diff --git a/web/api/write/network-add b/web/api/write/network-add
index d1aab4e..d1aab4e 100644..100755
--- a/web/api/write/network-add
+++ b/web/api/write/network-add
diff --git a/web/api/write/network-update b/web/api/write/network-update
index f6684c5..6344c37 100644..100755
--- a/web/api/write/network-update
+++ b/web/api/write/network-update
@@ -23,51 +23,23 @@ my @dups;
my $sth = $nms::web::dbh->prepare("SELECT name FROM networks WHERE name=?");
-my @fields = ('name','last_updated','placement','subnet4','subnet6','gw4','gw6','routing_point','vlan','tags');
-
-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;
-}
+my @fields = ('name','last_updated','subnet4','subnet6','gw4','gw6','routing_point','vlan','tags');
foreach my $tmp2 (@tmp) {
my %network = %{$tmp2};
my $affected = 0;
my %template = ();
map { $template{$_} = 'DEFAULT' } @fields;
- if (not defined($network{'sysname'})) {
+ if (not defined($network{'name'})) {
next;
}
- $sth->execute( $network{'sysname'});
+ $sth->execute( $network{'name'});
while ( my @row = $sth->fetchrow_array ) {
$affected += 1;
}
if ($affected == 0) {
- my %placement;
- if (not defined ($network{'placement'})) {
- %placement = guess_placement($network{'sysname'});
- } else {
- %placement = %{convertplace($network{'sysname'})};
- }
- my ($x1,$x2,$y1,$y2);
- $x1 = $placement{'x1'};
- $y1 = $placement{'y1'};
- $x2 = $placement{'xx'};
- $y2 = $placement{'yy'};
- $network{'placement'} = "(($x1,$y1),($x2,$y2))";
map {
if (defined ($template{$_})) {
@@ -76,24 +48,9 @@ foreach my $tmp2 (@tmp) {
} keys %network;
- $nms::web::dbh->do("INSERT INTO NETWORKS (name, last_updated, placement, subnet4, subnet6, routing_point, gw4, gw6, vlan, tags) VALUES ($template{'sysname'}, $template{'last_updated'}, $template{'placement'}, $template{'subnet4'}, $template{'subnet6'}, $template{'routing_point'}, $template{'gw4'}, $template{'gw6'}, $template{'vlan'}, $template{'tags'});");
- push @added, $network{'sysname'};
+ $nms::web::dbh->do("INSERT INTO NETWORKS (name, last_updated, subnet4, subnet6, routing_point, gw4, gw6, vlan, tags) VALUES ($template{'name'}, $template{'last_updated'}, $template{'subnet4'}, $template{'subnet6'}, $template{'routing_point'}, $template{'gw4'}, $template{'gw6'}, $template{'vlan'}, $template{'tags'});");
+ push @added, $network{'name'};
} else {
- if (defined($network{'placement'})) {
- my %placement;
- if ($network{'placement'} eq "reset") {
- %placement = guess_placement($network{'sysname'});
- } else {
- %placement = %{convertplace($network{'placement'})};
- }
- my ($x1,$x2,$y1,$y2);
- $x1 = $placement{'x1'};
- $y1 = $placement{'y1'};
- $x2 = $placement{'xx'};
- $y2 = $placement{'yy'};
- $network{'placement'} = "(($x1,$y1),($x2,$y2))";
- push @dups, "not really, but: " . $network{'placement'};
- }
if (defined($network{'tags'})) {
$network{'tags'} =~ s/'/"/g;
}
@@ -103,8 +60,8 @@ foreach my $tmp2 (@tmp) {
push @set, "$_=" . $dbh->quote($network{$_});
}
} keys %network;
- $nms::web::dbh->do("UPDATE NETWORKS SET " . join(", ", @set) . "WHERE name=" . $dbh->quote($network{'sysname'}) . ";");
- push @dups, $network{'sysname'};
+ $nms::web::dbh->do("UPDATE networks SET " . join(", ", @set) . "WHERE name=" . $dbh->quote($network{'name'}) . ";");
+ push @dups, $network{'name'};
}
}
$json{'networks_addded'} = \@added;
diff --git a/web/api/write/switch-update b/web/api/write/switch-update
index b71548b..bcf69e1 100755
--- a/web/api/write/switch-update
+++ b/web/api/write/switch-update
@@ -23,7 +23,7 @@ my @dups;
my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-my @fields = ( 'community', 'tags', 'distro_name', 'distro_phy_port', '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', 'sysname', 'traffic_vlan', 'deleted');
+my @fields = ( 'community', 'tags', 'distro_name', 'distro_phy_port', 'mgmt_v4_addr', 'mgmt_v6_addr', 'mgmt_vlan', 'placement', 'poll_frequency', 'sysname', 'traffic_vlan', 'deleted');
sub convertplace
{