From dcb45e4cad83c83e66ca7125a4f3350f475530bc Mon Sep 17 00:00:00 2001 From: Christian Ramseyer Date: Sat, 25 Apr 2020 17:32:01 +0200 Subject: [PATCH] Fix previous commit * revert unwanted commit of bogus Web/Plugin/Device/Modules.pm * commit actual fix for #710 --- lib/App/Netdisco/Web/Plugin/Device/Modules.pm | 13 ------------- lib/App/Netdisco/Worker/Plugin/Discover/Entities.pm | 12 ++++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/App/Netdisco/Web/Plugin/Device/Modules.pm b/lib/App/Netdisco/Web/Plugin/Device/Modules.pm index 3a9c79e4..9917d59f 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Modules.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Modules.pm @@ -17,22 +17,9 @@ ajax '/ajax/content/device/modules' => require_login sub { ->search_for_device($q) or send_error('Bad device', 400); my @set = $device->modules->search({}, {order_by => { -asc => [qw/parent class pos index/] }}); - # sort modules (empty set would be a 'no records' msg) my $results = &App::Netdisco::Util::Web::sort_modules( \@set ); return unless scalar %$results; - use Data::Dumper; - #print STDERR "-----------\n"; print STDERR Dumper($results); - - print STDERR "-----------\n"; - print STDERR Dumper($results->{root}) ."\n"; - print STDERR "-----------\n"; - my $id = 1; - print STDERR Dumper($results->{$id}{module}->name) ."\n"; - print STDERR Dumper($results->{$id}{module}->index) ."\n"; - print STDERR Dumper($results->{$id}{module}->parent) ."\n"; - print STDERR Dumper($results->{$id}->{children}) ."\n"; - print STDERR "-----------\n"; content_type('text/html'); template 'ajax/device/modules.tt', { diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Entities.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Entities.pm index 71ddcd5a..d901df66 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Entities.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Entities.pm @@ -91,6 +91,18 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { }; } + foreach my $m (@modules){ + unless ($seen_idx{$m->{parent}} || !$m->{parent}){ + # Some combined devices like Nexus with FEX or ASR with Satellites can return invalid + # EntityMIB trees. This workaround relocates entitites with invalid parents to the root + # of the tree, so they are at least visible in the Modules tab (see #710) + + info sprintf ' [%s] Entity %s (%s) has invalid parent %s - attaching as root entity instead', + $device->ip, $m->{index}, $m->{name}, $m->{parent}; + $m->{parent} = undef; + } + } + schema('netdisco')->txn_do(sub { my $gone = $device->modules->delete; debug sprintf ' [%s] modules - removed %d chassis modules',