From 3877f4d3a4389050250aa34474cabee6826f208f Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sat, 12 Mar 2016 13:52:52 +0000 Subject: NMS: Fix switch updates (better) --- web/nms.gathering.org/api/private/switch-add | 32 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 826b65b..5abe0f4 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -39,22 +39,25 @@ foreach my $tmp2 (@tmp) { } if ($affected == 0) { + my %placement; + if (not defined ($switch{'placement'})) { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{$switch{'placement'}}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + map { if (defined ($template{$_})) { - $template{$_} = $dbh->quote($switch{$_}); + $template{$_} = $dbh->quote($switch{$_}); } } keys %switch; - if (not defined($switch{'placement'})) { - %{$switch{'placement'}} = guess_placement($switch{'sysname'}); - } - my ($x1,$x2,$y1,$y2); - $x1 = $switch{'placement'}{'x1'}; - $y1 = $switch{'placement'}{'y1'}; - $x2 = $switch{'placement'}{'xx'}; - $y2 = $switch{'placement'}{'yy'}; - my $place = "(($x1,$y1),($x2,$y2))"; - $template{'placement'} = $dbh->quote($place); $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});"); push @added, $switch{'sysname'}; @@ -65,12 +68,13 @@ foreach my $tmp2 (@tmp) { $y1 = $switch{'placement'}{'y1'}; $x2 = $switch{'placement'}{'xx'}; $y2 = $switch{'placement'}{'yy'}; - my $place = "(($x1,$y1),($x2,$y2))"; - $switch{'placement'} = $place; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; } my @set; map { - push @set, "$_=" . $dbh->quote($switch{$_}); + if (defined($template{$_})) { + push @set, "$_=" . $dbh->quote($switch{$_}); + } } keys %switch; $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";"); push @dups, $switch{'sysname'}; -- cgit v1.2.3 From d1bb2ca6fced92b2d592e195126a3b28b73907b9 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sun, 13 Mar 2016 01:13:53 +0000 Subject: NMS: Fix comment changing --- web/nms.gathering.org/api/private/comment-change | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/comment-change b/web/nms.gathering.org/api/private/comment-change index ccf336d..fb7da54 100755 --- a/web/nms.gathering.org/api/private/comment-change +++ b/web/nms.gathering.org/api/private/comment-change @@ -3,12 +3,16 @@ use lib '../../../../include'; use utf8; use nms; -use nms::web; +use nms::web qw($dbh db_safe_quote get_input finalize_output); + use strict; use warnings; -my $id = db_safe_quote('comment'); -my $state = db_safe_quote('state'); +my $in = get_input(); +my %tmp = %{JSON::XS::decode_json($in)}; + +my $id = $dbh->quote($tmp{'comment'}); +my $state = $dbh->quote($tmp{'state'}); my $q = $nms::web::dbh->prepare("UPDATE switch_comments SET state = " . $state . " WHERE id = " . $id . ";"); $q->execute(); -- cgit v1.2.3 From 9f992ae24299d81643188530bc6f79e76f141c03 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sun, 13 Mar 2016 12:55:06 +0000 Subject: NMS: Pick up IP's properly Nobody look because I just defaulted to ipv4. --- web/nms.gathering.org/api/private/switch-add | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 5abe0f4..93416ff 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -45,6 +45,9 @@ foreach my $tmp2 (@tmp) { } else { %placement = %{$switch{'placement'}}; } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } my ($x1,$x2,$y1,$y2); $x1 = $placement{'x1'}; $y1 = $placement{'y1'}; @@ -70,6 +73,9 @@ foreach my $tmp2 (@tmp) { $y2 = $switch{'placement'}{'yy'}; $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } my @set; map { if (defined($template{$_})) { -- cgit v1.2.3 From 544368f68e6a55ed619b91f631b0e200ad7ed5ad Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sun, 13 Mar 2016 14:17:30 +0000 Subject: NMS: Allow editing switches in GUI It's not pretty, but it works and should cover most of the use-cases. Placement-editing is not meant to be the primary way to edit anything. --- web/nms.gathering.org/api/private/switch-add | 27 ++++++++++++++++++---- .../api/private/switches-management | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 93416ff..64e5e58 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -24,6 +24,22 @@ my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?" my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'placement'); +sub convertplace +{ + my %in = %{$_[0]}; + my %out = (); + + if (not defined $in{'x1'} and defined($in{'x'})) { + $out{'x1'} = $in{'x'}; + $out{'y1'} = $in{'y'}; + $out{'xx'} = $in{'x'} + $in{'width'}; + $out{'yy'} = $in{'y'} + $in{'height'}; + } else { + return \%in; + } + return \%out; +} + foreach my $tmp2 (@tmp) { my %switch = %{$tmp2}; my $affected = 0; @@ -43,7 +59,7 @@ foreach my $tmp2 (@tmp) { if (not defined ($switch{'placement'})) { %placement = guess_placement($switch{'sysname'}); } else { - %placement = %{$switch{'placement'}}; + %placement = %{convertplace($switch{'placement'})}; } if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { $switch{'ip'} = $switch{'mgtmt4'}; @@ -66,11 +82,12 @@ foreach my $tmp2 (@tmp) { push @added, $switch{'sysname'}; } else { if (defined($switch{'placement'})) { + my %placement = %{convertplace($switch{'placement'})}; my ($x1,$x2,$y1,$y2); - $x1 = $switch{'placement'}{'x1'}; - $y1 = $switch{'placement'}{'y1'}; - $x2 = $switch{'placement'}{'xx'}; - $y2 = $switch{'placement'}{'yy'}; + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; } if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { diff --git a/web/nms.gathering.org/api/private/switches-management b/web/nms.gathering.org/api/private/switches-management index 474f674..a598824 100755 --- a/web/nms.gathering.org/api/private/switches-management +++ b/web/nms.gathering.org/api/private/switches-management @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select sysname,ip,switchtype,poll_frequency,community,last_updated from switches '); +my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,community,last_updated from switches '); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { -- cgit v1.2.3 From e7eb548d99a324048d6fd08cb5a0243e47753451 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sun, 13 Mar 2016 15:54:14 +0000 Subject: NMSjs: Enable interactive movement of switches! Fixes #24 God that felt good. It's not very pretty, but it does seem very functional. --- web/nms.gathering.org/api/private/switch-add | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 64e5e58..e177b5e 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -30,10 +30,10 @@ sub convertplace my %out = (); if (not defined $in{'x1'} and defined($in{'x'})) { - $out{'x1'} = $in{'x'}; - $out{'y1'} = $in{'y'}; - $out{'xx'} = $in{'x'} + $in{'width'}; - $out{'yy'} = $in{'y'} + $in{'height'}; + $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; } @@ -89,6 +89,7 @@ foreach my $tmp2 (@tmp) { $x2 = $placement{'xx'}; $y2 = $placement{'yy'}; $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + push @dups, "not really, but: " . $switch{'placement'}; } if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { $switch{'ip'} = $switch{'mgtmt4'}; -- cgit v1.2.3 From a9656e1fa4bcec5bcbbfe5ca29671d6701014ce8 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sun, 13 Mar 2016 17:07:28 +0000 Subject: NMS: Support resetting switch position to buest-guess Simply type "reset" in the gui (including quotes) and it'll guess based on name. --- web/nms.gathering.org/api/private/switch-add | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index e177b5e..92479f0 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -82,7 +82,12 @@ foreach my $tmp2 (@tmp) { push @added, $switch{'sysname'}; } else { if (defined($switch{'placement'})) { - my %placement = %{convertplace($switch{'placement'})}; + my %placement; + if ($switch{'placement'} eq "reset") { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } my ($x1,$x2,$y1,$y2); $x1 = $placement{'x1'}; $y1 = $placement{'y1'}; -- cgit v1.2.3 From e3244501e89df95c6cb3ad2b9efc7e708ec9b1bb Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 16 Mar 2016 19:55:11 +0000 Subject: NMS: Fix production-grade cache :D Seems to work fine, both with caching and cache invalidation. (e.g.: moving a switch, adding ac omment). Might have missed something, of course. --- web/nms.gathering.org/api/private/comment-add | 1 + web/nms.gathering.org/api/private/switch-add | 1 + 2 files changed, 2 insertions(+) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/comment-add b/web/nms.gathering.org/api/private/comment-add index 2f8b0b7..26ff734 100755 --- a/web/nms.gathering.org/api/private/comment-add +++ b/web/nms.gathering.org/api/private/comment-add @@ -20,4 +20,5 @@ $nms::web::cc{'max-age'} = '0'; $nms::web::cc{'stale-while-revalidate'} = '0'; $nms::web::json{'state'} = 'ok'; +print "X-ban: /api/private/comments\n"; finalize_output(); diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 92479f0..e50b9a5 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -112,4 +112,5 @@ foreach my $tmp2 (@tmp) { $json{'switches_addded'} = \@added; $json{'switches_updated'} = \@dups; +print "X-ban: /api/.*switches.*\n"; finalize_output(); -- cgit v1.2.3 From 06aad5822ec9630f23284f85ad057027e7448a3e Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 16 Mar 2016 22:11:07 +0000 Subject: NMS: ... actually add the SNMP API "Untracked files".... --- web/nms.gathering.org/api/private/snmp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 web/nms.gathering.org/api/private/snmp (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/snmp b/web/nms.gathering.org/api/private/snmp new file mode 100755 index 0000000..4779659 --- /dev/null +++ b/web/nms.gathering.org/api/private/snmp @@ -0,0 +1,29 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web; +use strict; +use warnings; +use JSON; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "10"; + +my $q = $nms::web::dbh->prepare('select sysname,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch);'); + +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + my $sysname = $ref->{'sysname'}; + + # This is, strictly speaking, redundant. But by doing this, we can + # re-use the standard methods of finalize_output() and whatnot. + my $data = JSON::XS::decode_json($ref->{'data'}); + + $nms::web::json{'snmp'}{$ref->{'sysname'}} = $data; +} + +finalize_output(); -- cgit v1.2.3 From 888e40e600f4851e62d213eb0db3122e8d72c5a5 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 16 Mar 2016 22:37:26 +0000 Subject: NMS: Nuke port-state, update switch-state On its way. Not done. --- web/nms.gathering.org/api/private/port-state | 33 ---------------------------- 1 file changed, 33 deletions(-) delete mode 100755 web/nms.gathering.org/api/private/port-state (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/port-state b/web/nms.gathering.org/api/private/port-state deleted file mode 100755 index 8c6b64c..0000000 --- a/web/nms.gathering.org/api/private/port-state +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -use lib '../../../../include'; -use nms::web; -use strict; -use warnings; - -my $query = 'select sysname,extract(epoch from date_trunc(\'second\',time)) as time, ifname,ifhighspeed,ifhcinoctets,ifhcoutoctets from polls natural join switches where time in (select max(time) from polls where ' . $nms::web::when . ' group by switch,ifname);'; -my $q = $nms::web::dbh->prepare($query); -$q->execute(); - -while (my $ref = $q->fetchrow_hashref()) { - my @fields = ('ifhighspeed','ifhcoutoctets','ifhcinoctets'); - foreach my $val (@fields) { - $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{$val} = $ref->{$val}; - } - $nms::web::json{'switches'}{$ref->{'sysname'}}{'ports'}{$ref->{'ifname'}}{'time'} = $ref->{'time'}; -} - -my $q3 = $nms::web::dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $nms::web::when . ' order by switch,time desc'); - - -$q3->execute(); -while (my $ref = $q3->fetchrow_hashref()) { - my $sysname = $ref->{'sysname'}; - $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp'} = $ref->{'temp'}; - $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp_time'} = $ref->{'time'}; -} -$nms::web::cc{'max-age'} = '2'; -$nms::web::cc{'stale-while-revalidate'} = '120'; - -finalize_output(); -- cgit v1.2.3 From 025f01e7e8c5bfea21b559fbac650f90c2774a29 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Thu, 17 Mar 2016 19:50:13 +0000 Subject: NMS: Add subnets in swtiches --- web/nms.gathering.org/api/private/switch-add | 2 +- web/nms.gathering.org/api/private/switches-management | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api/private') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index e50b9a5..979a1d8 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -22,7 +22,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'placement'); +my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement'); sub convertplace { diff --git a/web/nms.gathering.org/api/private/switches-management b/web/nms.gathering.org/api/private/switches-management index a598824..543d08d 100755 --- a/web/nms.gathering.org/api/private/switches-management +++ b/web/nms.gathering.org/api/private/switches-management @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,community,last_updated from switches '); +my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,community,subnet4,subnet6,last_updated from switches '); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { -- cgit v1.2.3