#1072 clean custom_fields keys on rediscover

This commit is contained in:
Oliver Gorwits
2023-07-20 12:49:40 +01:00
parent f8222e7890
commit 31489ba550
3 changed files with 14 additions and 8 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {