aboutsummaryrefslogtreecommitdiffstats
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
parent8607a0880724eca35c220f7c26a138d9f0f50f72 (diff)
Added support for delete switches
-rwxr-xr-xcollectors/dhcptail.pl4
-rwxr-xr-xcollectors/ping.pl2
-rwxr-xr-xcollectors/snmpfetchng.pl2
-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
-rwxr-xr-xweb/api/read/distro-management2
-rwxr-xr-xweb/api/read/switches-management4
-rwxr-xr-xweb/api/write/switch-update2
-rw-r--r--web/js/nms-draw-chart.js8
-rw-r--r--web/js/nms-info-box.js26
13 files changed, 48 insertions, 21 deletions
diff --git a/collectors/dhcptail.pl b/collectors/dhcptail.pl
index 857bf5e..5fd8cf0 100755
--- a/collectors/dhcptail.pl
+++ b/collectors/dhcptail.pl
@@ -7,7 +7,7 @@ use strict;
use Data::Dumper;
use warnings;
-my $year = 2016;
+my $year = 2018;
my %months = (
Jan => 1,
@@ -27,7 +27,7 @@ my %months = (
my $realtime = 0;
my ($dbh, $q,$check);
$dbh = nms::db_connect();
-$q = $dbh->prepare("INSERT INTO dhcp (dhcp_server,switch,time,ip,mac) VALUES($nms::config::dhcp_id,(SELECT switch FROM switches WHERE ?::inet << subnet4 ORDER BY sysname LIMIT 1),?,?,?)");
+$q = $dbh->prepare("INSERT INTO dhcp (dhcp_server,switch,time,ip,mac) VALUES($nms::config::dhcp_id,(SELECT switch FROM switches WHERE ?::inet << subnet4 and deleted = false ORDER BY sysname LIMIT 1),?,?,?)");
$check = $dbh->prepare("SELECT max(time)::timestamp - ?::timestamp < '0s'::interval as doit FROM dhcp where dhcp_server = $nms::config::dhcp_id;");
open(SYSLOG, "tail -n 9999999 -F /var/log/messages |") or die "Unable to tail syslog: $!";
diff --git a/collectors/ping.pl b/collectors/ping.pl
index 952932a..82c5c42 100755
--- a/collectors/ping.pl
+++ b/collectors/ping.pl
@@ -18,7 +18,7 @@ $dbh->{RaiseError} = 1;
my $influx = nms::influx_connect();
-my $q = $dbh->prepare("SELECT switch,sysname,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null or mgmt_v6_addr is not null ORDER BY random();");
+my $q = $dbh->prepare("SELECT switch,sysname,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE switches.deleted = false and (mgmt_v4_addr is not null or mgmt_v6_addr is not null) ORDER BY random();");
my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null;");
my $last = time();
diff --git a/collectors/snmpfetchng.pl b/collectors/snmpfetchng.pl
index 0ace8c4..9c06f4a 100755
--- a/collectors/snmpfetchng.pl
+++ b/collectors/snmpfetchng.pl
@@ -26,7 +26,7 @@ my $influx = nms::influx_connect();
my $qualification = <<"EOF";
(last_updated IS NULL OR now() - last_updated > poll_frequency)
AND (locked='f' OR now() - last_updated > '15 minutes'::interval)
-AND (mgmt_v4_addr is not null or mgmt_v6_addr is not null)
+AND (mgmt_v4_addr is not null or mgmt_v6_addr is not null) AND deleted = false
EOF
# Borrowed from snmpfetch.pl
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()) {
diff --git a/web/api/read/distro-management b/web/api/read/distro-management
index 2aa3273..7fbebef 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');
+$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->execute();
while (my $ref = $q2->fetchrow_hashref()) {
diff --git a/web/api/read/switches-management b/web/api/read/switches-management
index 9d8bc53..9182b60 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 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');
} 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,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->execute();
diff --git a/web/api/write/switch-update b/web/api/write/switch-update
index 0ee4681..b71548b 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');
+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');
sub convertplace
{
diff --git a/web/js/nms-draw-chart.js b/web/js/nms-draw-chart.js
index b45d771..ca5e244 100644
--- a/web/js/nms-draw-chart.js
+++ b/web/js/nms-draw-chart.js
@@ -124,14 +124,14 @@ function drawSumOfPorts(canvas, sw) {
serie['values'].forEach(function(element) {
data.push({t: new Date(element[0]), y: element[1] / size_divider });
});
- dataset.push({data: data, backgroundColor:'rgba(38,105,28,200)', label:'Traffic in (' + sizeToText(size)+')'});
+ dataset.push({data: data, backgroundColor:'rgba(58,125,48,200)', label:'Traffic in (' + sizeToText(size)+')'});
// Bytes out
data = [];
serie['values'].forEach(function(element) {
data.push({t: new Date(element[0]), y: -Math.abs(element[2] / size_divider) });
});
- dataset.push({data: data, backgroundColor:'rgba(64,64,122,225)', label:'Traffic out (' + sizeToText(size)+')'});
+ dataset.push({data: data, backgroundColor:'rgba(84,84,142,225)', label:'Traffic out (' + sizeToText(size)+')'});
});
@@ -256,14 +256,14 @@ function drawPort(canvas, sw, port) {
serie['values'].forEach(function(element) {
data.push({t: new Date(element[0]), y: element[1] / size_divider });
});
- dataset.push({data: data, backgroundColor:'rgba(38,105,28,200)', label:'Traffic in (' + sizeToText(size)+')'});
+ dataset.push({data: data, backgroundColor:'rgba(58,125,48,200)', label:'Traffic in (' + sizeToText(size)+')'});
// Bytes out
data = [];
serie['values'].forEach(function(element) {
data.push({t: new Date(element[0]), y: -Math.abs(element[2] / size_divider) });
});
- dataset.push({data: data, backgroundColor:'rgba(64,64,122,225)', label:'Traffic out (' + sizeToText(size)+')'});
+ dataset.push({data: data, backgroundColor:'rgba(84,84,142,225)', label:'Traffic out (' + sizeToText(size)+')'});
// Draw the chart
diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js
index 9a5edae..f1d1fa4 100644
--- a/web/js/nms-info-box.js
+++ b/web/js/nms-info-box.js
@@ -981,8 +981,16 @@ var switchEditPanel = function () {
submit.classList.add("btn", "btn-primary");
submit.id = "edit-submit-" + this.sw;
submit.setAttribute("onclick","nmsInfoBox._windowHandler.doInPanel('" + this.id + "','save');");
+ submit.style = "margin-right: 5px";
nav.appendChild(submit);
+ var deleteButton = document.createElement("button");
+ deleteButton.innerHTML = "Delete switch";
+ deleteButton.classList.add("btn", "btn-danger");
+ deleteButton.id = "delete-submit-" + this.sw;
+ deleteButton.setAttribute("onclick","nmsInfoBox._windowHandler.doInPanel('" + this.id + "','deleteSwitch');");
+ nav.appendChild(deleteButton);
+
var toggleDetails = document.createElement("button");
toggleDetails.innerHTML = '<span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span>';
toggleDetails.classList.add("btn", "btn-default", "pull-right");
@@ -1026,6 +1034,24 @@ var switchEditPanel = function () {
}
});
};
+
+ this.deleteSwitch = function () {
+ if(confirm("This will delete the switch: " + this.sw)) {
+ var myData = [{'sysname': this.sw, 'deleted': true}];
+ myData = JSON.stringify(myData);
+ $.ajax({
+ type: "POST",
+ url: "/api/write/switch-update",
+ dataType: "text",
+ data:myData,
+ success: function (data, textStatus, jqXHR) {
+ nmsInfoBox.hide();
+ nmsData.invalidate("switches");
+ nmsData.invalidate("smanagement");
+ }
+ });
+ };
+ };
};
nmsInfoBox.addPanelType("switchEdit",switchEditPanel);