From 31489ba550b24d6aa3e21a05dadd2ae4ed0c5cf6 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 20 Jul 2023 12:49:40 +0100 Subject: [PATCH] #1072 clean custom_fields keys on rediscover --- lib/App/Netdisco/JobQueue/PostgreSQL.pm | 8 ++++++-- lib/App/Netdisco/Web/CustomFields.pm | 3 --- lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm | 11 ++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/lib/App/Netdisco/JobQueue/PostgreSQL.pm index 30193eca..f679b68b 100644 --- a/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -340,14 +340,18 @@ sub jq_insert { ->find($spec->{port}, $spec->{device}); undef $row unless scalar grep {('cf_'. $_) eq $spec->{action}} - @{ setting('_device_port_custom_fields') || [] }; + grep {defined} + map {$_->{name}} + @{ setting('custom_fields')->{device_port} || [] }; } else { $row = schema(vars->{'tenant'})->resultset('Device') ->find($spec->{device}); undef $row unless scalar grep {('cf_'. $_) eq $spec->{action}} - @{ setting('_device_custom_fields') || [] }; + grep {defined} + map {$_->{name}} + @{ setting('custom_fields')->{device} || [] }; } die 'failed to find row for custom field update' unless $row; diff --git a/lib/App/Netdisco/Web/CustomFields.pm b/lib/App/Netdisco/Web/CustomFields.pm index 217a8ea5..05dfc5b4 100644 --- a/lib/App/Netdisco/Web/CustomFields.pm +++ b/lib/App/Netdisco/Web/CustomFields.pm @@ -83,7 +83,4 @@ set('_inline_actions' => [ map {'cf_' . $_} (@inline_device_actions, @inline_device_port_actions) ]); -set('_device_custom_fields' => \@inline_device_actions); -set('_device_port_custom_fields' => \@inline_device_port_actions); - true; diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm index 063a605f..40a76b71 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm @@ -11,7 +11,6 @@ use App::Netdisco::Util::Device 'get_device'; use App::Netdisco::Util::DNS 'hostname_from_ip'; use App::Netdisco::Util::SNMP 'snmp_comm_reindex'; use App::Netdisco::Util::Web 'sort_port'; -use App::Netdisco::Web::CustomFields; use Dancer::Plugin::DBIC 'schema'; use Scope::Guard 'guard'; @@ -81,7 +80,10 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub { if ($device->in_storage) { # get the custom_fields my $fields = from_json ($device->custom_fields || '{}'); - my %ok_fields = map {$_ => 1} @{ setting('_device_custom_fields') || [] }; + my %ok_fields = map {$_ => 1} + grep {defined} + map {$_->{name}} + @{ setting('custom_fields')->{device} || [] }; # filter custom_fields for current valid fields foreach my $field (keys %$fields) { @@ -388,7 +390,10 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub { ->search(undef, {columns => [qw/port custom_fields/]}) ->hri->all; - my %ok_fields = map {$_ => 1} @{ setting('_device_port_custom_fields') || [] }; + my %ok_fields = map {$_ => 1} + grep {defined} + map {$_->{name}} + @{ setting('custom_fields')->{device_port} || [] }; # filter custom_fields for current valid fields foreach my $port (keys %fields) {