From 62d92df44a8eef749ab2b1fddf283af76122852c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 29 Jul 2014 13:10:48 +0100 Subject: [PATCH 1/7] [#122] CDP/LLDP discovery for some HP switches (M. Kosmach) --- Netdisco/Changes | 6 ++++++ Netdisco/lib/App/Netdisco/Core/Discover.pm | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 117ba8f9..f973a84b 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,3 +1,9 @@ +2.028013 + + [ENHANCEMENTS] + + * [#122] CDP/LLDP discovery for some HP switches (M. Kosmach) + 2.028012 - 2014-07-22 [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/Core/Discover.pm b/Netdisco/lib/App/Netdisco/Core/Discover.pm index dbacbbdd..48ead720 100644 --- a/Netdisco/lib/App/Netdisco/Core/Discover.pm +++ b/Netdisco/lib/App/Netdisco/Core/Discover.pm @@ -730,7 +730,22 @@ sub store_neighbors { if (!defined $neigh) { my $mac = Net::MAC->new(mac => $remote_id, 'die' => 0, verbose => 0); if (not $mac->get_error) { - $neigh = $devices->single({mac => $remote_id}); + $neigh = $devices->single({mac => $mac->as_IEEE()}); + } + } + + # some HP switches send 127.0.0.1 as remote_ip if no ip address + # on default vlan for HP switches remote_ip looks like + # "myswitchname(012345-012345)" + if (!defined $neigh) { + (my $tmpid = $remote_id) =~ s/.([0-9a-f]{6})-([0-9a-f]{6})./$1$2/; + my $mac = Net::MAC->new(mac => $tmpid, 'die' => 0, verbose => 0); + + if (not $mac->get_error) { + info sprintf + '[%s] neigh - found neighbor %s by MAC %s', + $device->ip, $remote_id, $mac->as_IEEE(); + $neigh = $devices->single({mac => $mac->as_IEEE()}); } } From 8e35a7158eb57efb93513f4f541c3bd5744c62ac Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 31 Jul 2014 00:54:58 +0100 Subject: [PATCH 2/7] fix when interactives set to zero --- Netdisco/Changes | 4 ++++ Netdisco/lib/App/Netdisco/Configuration.pm | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index f973a84b..7f79d7b6 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -4,6 +4,10 @@ * [#122] CDP/LLDP discovery for some HP switches (M. Kosmach) + [BUG FIXES] + + * Fix when Interactives number set to zero + 2.028012 - 2014-07-22 [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/Configuration.pm b/Netdisco/lib/App/Netdisco/Configuration.pm index 2dc444bc..91bec56c 100644 --- a/Netdisco/lib/App/Netdisco/Configuration.pm +++ b/Netdisco/lib/App/Netdisco/Configuration.pm @@ -43,7 +43,8 @@ setting('plugins')->{DBIC}->{daemon} = { # defaults for workers setting('workers')->{queue} ||= 'PostgreSQL'; -setting('workers')->{interactives} ||= 1; +setting('workers')->{interactives} = 1 + if setting('workers') and not exists setting('workers')->{interactives}; # force skipped DNS resolution, if unset setting('dns')->{hosts_file} ||= '/etc/hosts'; From 24028557974ef4956e0d6efc35fe42f14ba47142 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 31 Jul 2014 00:55:56 +0100 Subject: [PATCH 3/7] Daemon crash when restarting with in-progress jobs and many workers --- Netdisco/Changes | 1 + Netdisco/bin/netdisco-daemon-fg | 4 ++-- Netdisco/lib/App/Netdisco/Daemon/LocalQueue.pm | 9 ++++++++- Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm | 9 ++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 7f79d7b6..9a1be270 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -7,6 +7,7 @@ [BUG FIXES] * Fix when Interactives number set to zero + * [#121] Daemon crash when restarting with in-progress jobs and many workers 2.028012 - 2014-07-22 diff --git a/Netdisco/bin/netdisco-daemon-fg b/Netdisco/bin/netdisco-daemon-fg index 6b763ab6..f10e332c 100755 --- a/Netdisco/bin/netdisco-daemon-fg +++ b/Netdisco/bin/netdisco-daemon-fg @@ -38,7 +38,7 @@ my $mce = MCE->new( job_delay => 1.15, tmp_dir => $tmp_dir, user_func => sub { $_[0]->worker_body }, - on_post_exit => \&restart_worker, + on_post_exit => \&restart_this_worker, user_tasks => build_tasks_list(), )->run(); @@ -97,7 +97,7 @@ sub worker_factory { }; } -sub restart_worker { +sub restart_this_worker { my ($self, $e) = @_; reset_jobs($e->{wid}); diff --git a/Netdisco/lib/App/Netdisco/Daemon/LocalQueue.pm b/Netdisco/lib/App/Netdisco/Daemon/LocalQueue.pm index 13834a3f..b3dbcb9a 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/LocalQueue.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/LocalQueue.pm @@ -5,7 +5,7 @@ use Dancer::Plugin::DBIC 'schema'; use base 'Exporter'; our @EXPORT = (); -our @EXPORT_OK = qw/ add_jobs capacity_for take_jobs reset_jobs/; +our @EXPORT_OK = qw/ add_jobs capacity_for take_jobs reset_jobs release_jobs /; our %EXPORT_TAGS = ( all => \@EXPORT_OK ); schema('daemon')->deploy; @@ -59,4 +59,11 @@ sub reset_jobs { ->update({wid => 0}); } +# not used by workers, only the daemon when reinitializing a worker +sub release_jobs { + my ($jid) = @_; + debug "releasing local job ID $jid"; + $queue->search({job => $jid})->delete; +} + 1; diff --git a/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm index ffd89ef7..dc66f6af 100644 --- a/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -143,12 +143,19 @@ sub jq_lock { return $happy; } +# PostgreSQL engine depends on LocalQueue, which is accessed synchronously via +# the main daemon process. This is only used by daemon workers which can use +# MCE ->do() method. sub jq_defer { my $job = shift; my $happy = false; - # lock db row and update to show job is available try { + # other local workers are polling the central queue, so + # to prevent a race, first delete the job in our local queue + MCE->do('release_jobs', $job->id); + + # lock db row and update to show job is available schema('netdisco')->txn_do(sub { schema('netdisco')->resultset('Admin') ->find($job->id, {for => 'update'}) From 838adb087bd2aa3fc1d5fba453bebd7f3e52e6cf Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 31 Jul 2014 00:56:44 +0100 Subject: [PATCH 4/7] release 2.028013 --- Netdisco/Changes | 2 +- Netdisco/META.yml | 2 +- Netdisco/lib/App/Netdisco.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 9a1be270..2835204c 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,4 +1,4 @@ -2.028013 +2.028013 - 2014-07-31 [ENHANCEMENTS] diff --git a/Netdisco/META.yml b/Netdisco/META.yml index fe65e38b..6d596879 100644 --- a/Netdisco/META.yml +++ b/Netdisco/META.yml @@ -81,4 +81,4 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/bsd-license.php repository: git://git.code.sf.net/p/netdisco/netdisco-ng -version: 2.028012 +version: 2.028013 diff --git a/Netdisco/lib/App/Netdisco.pm b/Netdisco/lib/App/Netdisco.pm index 879e6765..f52e472e 100644 --- a/Netdisco/lib/App/Netdisco.pm +++ b/Netdisco/lib/App/Netdisco.pm @@ -4,7 +4,7 @@ use strict; use warnings; use 5.010_000; -our $VERSION = '2.028012'; +our $VERSION = '2.028013'; use App::Netdisco::Configuration; =head1 NAME From f53c35acb999d3b8f45ea81e2e5f2247d4d3f25b Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 31 Jul 2014 11:42:26 +0100 Subject: [PATCH 5/7] Missing action to netdisco-do should not throw Perl error --- Netdisco/Changes | 6 ++++++ Netdisco/bin/netdisco-do | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 2835204c..ee309134 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,3 +1,9 @@ +2.028014 + + [BUG FIXES] + + * Missing action to netdisco-do should not throw Perl error + 2.028013 - 2014-07-31 [ENHANCEMENTS] diff --git a/Netdisco/bin/netdisco-do b/Netdisco/bin/netdisco-do index 58bd329b..7d6457b9 100755 --- a/Netdisco/bin/netdisco-do +++ b/Netdisco/bin/netdisco-do @@ -65,7 +65,7 @@ schema('daemon')->deploy; # get requested action my $action = shift @ARGV; -if (!length $action) { +unless ($action) { error 'error: missing action!'; exit (1); } From 2dbcc258437b71ebb2d2d37001cd872369dc86d8 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 31 Jul 2014 19:59:00 +0100 Subject: [PATCH 6/7] + * Sort CDP/LLDP data to be more consistent when multiple neighbors on a port + * Add "AP" as a hint for WAP support --- Netdisco/Changes | 2 ++ Netdisco/lib/App/Netdisco/Core/Discover.pm | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index ee309134..1ff39208 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -3,6 +3,8 @@ [BUG FIXES] * Missing action to netdisco-do should not throw Perl error + * Sort CDP/LLDP data to be more consistent when multiple neighbors on a port + * Add "AP" as a hint for WAP support 2.028013 - 2014-07-31 diff --git a/Netdisco/lib/App/Netdisco/Core/Discover.pm b/Netdisco/lib/App/Netdisco/Core/Discover.pm index 48ead720..779b92a2 100644 --- a/Netdisco/lib/App/Netdisco/Core/Discover.pm +++ b/Netdisco/lib/App/Netdisco/Core/Discover.pm @@ -666,7 +666,7 @@ sub store_neighbors { my $c_platform = $snmp->c_platform; my $c_cap = $snmp->c_cap; - foreach my $entry (List::MoreUtils::uniq( (keys %$c_ip), (keys %$c_cap) )) { + foreach my $entry (sort (List::MoreUtils::uniq( (keys %$c_ip), (keys %$c_cap) ))) { if (!defined $c_if->{$entry} or !defined $interfaces->{ $c_if->{$entry} }) { debug sprintf ' [%s] neigh - port for IID:%s not resolved, skipping', $device->ip, $entry; @@ -695,11 +695,11 @@ sub store_neighbors { my $phone_flag = grep {/phone/i} @$remote_cap; my $ap_flag = grep {/wlanAccessPoint/} @$remote_cap; - if ($phone_flag or $remote_type =~ m/(mitel.5\d{3})/i) { + if ($phone_flag or $remote_type =~ m/mitel.5\d{3}/i) { $remote_type = 'IP Phone: '. $remote_type if $remote_type !~ /ip phone/i; } - elsif ($ap_flag) { + elsif ($ap_flag or $remote_type =~ m/\bw?ap\b/i) { $remote_type = 'AP: '. $remote_type; } From 29d3ac707b9dcba5490d8acdac3f72197ceb03fd Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 31 Jul 2014 21:25:22 +0100 Subject: [PATCH 7/7] [#108] Port Bounce port control feature (down and up in succession) --- Netdisco/Changes | 4 ++ .../Daemon/Worker/Interactive/PortActions.pm | 11 +++- .../javascripts/netdisco_portcontrol.js | 58 ++++++++++--------- Netdisco/share/views/ajax/device/ports.tt | 26 ++++++--- 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 1ff39208..f88e712a 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,5 +1,9 @@ 2.028014 + [ENHANCEMENTS] + + * [#108] Port Bounce port control feature (down and up in succession) + [BUG FIXES] * Missing action to netdisco-do should not throw Perl error diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm index 917851a1..7adf941c 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm @@ -27,7 +27,16 @@ sub set_portcontrol { (my $sa = $job->subaction) =~ s/-\w+//; $job->subaction($sa); - return _set_port_generic($job, 'up_admin'); + if ($sa eq 'bounce') { + $job->subaction('down'); + my @stat = _set_port_generic($job, 'up_admin'); + return @stat if $stat[0] ne 'done'; + $job->subaction('up'); + return _set_port_generic($job, 'up_admin'); + } + else { + return _set_port_generic($job, 'up_admin'); + } } sub set_vlan { diff --git a/Netdisco/share/public/javascripts/netdisco_portcontrol.js b/Netdisco/share/public/javascripts/netdisco_portcontrol.js index e05eca43..edbd15e5 100644 --- a/Netdisco/share/public/javascripts/netdisco_portcontrol.js +++ b/Netdisco/share/public/javascripts/netdisco_portcontrol.js @@ -22,7 +22,7 @@ function port_control (e) { device: td.data('for-device') ,port: td.data('for-port') ,field: td.data('field') - ,action: td.data('action') + ,action: ($(e).data('action') || td.data('action')) ,value: td.text().trim() ,reason: reason ,log: logmessage @@ -30,31 +30,35 @@ function port_control (e) { ,success: function() { toastr.info('Submitted change request'); - // update all the screen furniture for port up/down control - if ($.trim(td.data('action')) == 'down') { - td.prev('td').html(''); - $(e).toggleClass('icon-hand-down'); - $(e).toggleClass('icon-hand-up'); - $(e).data('tooltip').options.title = 'Click to Enable'; - td.data('action', 'up'); - } - else if ($.trim(td.data('action')) == 'up') { - td.prev('td').html(''); - $(e).toggleClass('icon-hand-up'); - $(e).toggleClass('icon-hand-down'); - $(e).data('tooltip').options.title = 'Click to Disable'; - td.data('action', 'down'); - } - else if ($.trim(td.data('action')) == 'false') { - $(e).next('span').text(''); - $(e).toggleClass('nd_power-on'); - $(e).data('tooltip').options.title = 'Click to Enable'; - td.data('action', 'true'); - } - else if ($.trim(td.data('action')) == 'true') { - $(e).toggleClass('nd_power-on'); - $(e).data('tooltip').options.title = 'Click to Disable'; - td.data('action', 'false'); + // update all the screen furniture unless bouncing + if (! $(e).hasClass('icon-bullseye')) { + if ($.trim(td.data('action')) == 'down') { + td.prev('td').html(''); + $(e).toggleClass('icon-hand-down'); + $(e).toggleClass('icon-hand-up'); + $(e).siblings('.icon-bullseye').hide(); + $(e).data('tooltip').options.title = 'Enable Port'; + td.data('action', 'up'); + } + else if ($.trim(td.data('action')) == 'up') { + td.prev('td').html(''); + $(e).toggleClass('icon-hand-up'); + $(e).toggleClass('icon-hand-down'); + $(e).siblings('.icon-bullseye').show(); + $(e).data('tooltip').options.title = 'Disable Port'; + td.data('action', 'down'); + } + else if ($.trim(td.data('action')) == 'false') { + $(e).next('span').text(''); + $(e).toggleClass('nd_power-on'); + $(e).data('tooltip').options.title = 'Enable Power'; + td.data('action', 'true'); + } + else if ($.trim(td.data('action')) == 'true') { + $(e).toggleClass('nd_power-on'); + $(e).data('tooltip').options.title = 'Disable Power'; + td.data('action', 'false'); + } } } ,error: function() { @@ -118,7 +122,7 @@ $(document).ready(function() { }); // activity for port up/down control, power enable/disable control - $('#ports_pane').on('click', '.icon-hand-up,.icon-hand-down,.nd_power-icon', function() { + $('#ports_pane').on('click', '.icon-hand-up,.icon-hand-down,.nd_power-icon,.icon-bullseye', function() { var clicked = this; // create a closure $('#nd_portlog').one('hidden', function() { port_control(clicked); // save diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index c9053b28..b5a255cc 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -62,16 +62,26 @@ - + + + + [% ELSE %] - + + + + [% END %] @@ -208,7 +218,7 @@ + data-animation="" data-title="Disable Power"> [% ELSE %] @@ -228,7 +238,7 @@ + data-animation="" data-title="Enable Power"> [% ELSE %]