From 224bfbca525365b87f5adeef008dda078c89b5ea Mon Sep 17 00:00:00 2001 From: Ambroise Date: Fri, 5 Jun 2020 10:08:19 +0200 Subject: [PATCH] - add a function to avoid to have two times the same device exported in rancid config (#725) - avoid some strange warning message and add a default domain in makerancidconf plugin --- lib/App/Netdisco/Worker/Plugin/MakeRancidConf.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/App/Netdisco/Worker/Plugin/MakeRancidConf.pm b/lib/App/Netdisco/Worker/Plugin/MakeRancidConf.pm index 32ab43a1..53292bda 100644 --- a/lib/App/Netdisco/Worker/Plugin/MakeRancidConf.pm +++ b/lib/App/Netdisco/Worker/Plugin/MakeRancidConf.pm @@ -18,7 +18,7 @@ register_worker({ phase => 'main' }, sub { my ($job, $workerconf) = @_; my $config = setting('rancid') || {}; - my $domain_suffix = setting('domain_suffix'); + my $domain_suffix = setting('domain_suffix') || ''; my $delimiter = $config->{delimiter} || ';'; my $down_age = $config->{down_age} || '1 day'; my $default_group = $config->{default_group} || 'default'; @@ -62,6 +62,7 @@ register_worker({ phase => 'main' }, sub { } my $routerdb = {}; + my $routerunicity = {}; while (my $d = $devices->next) { if (check_acl_no($d, $config->{excluded})) { @@ -70,11 +71,16 @@ register_worker({ phase => 'main' }, sub { } my $name = check_acl_no($d, $config->{by_ip}) ? $d->ip : ($d->dns || $d->name); - $name =~ s/$domain_suffix// if check_acl_no($d, $config->{by_hostname}); + $name =~ s/$domain_suffix$// if check_acl_no($d, $config->{by_hostname}); my ($group) = (pairkeys pairfirst { check_acl_no($d, $b) } %{ $config->{groups} }) || $default_group; + if (exists($routerunicity->{$group}->{$name})) { + debug " skipping $d: device excluded because already present in export list"; + next; + } + my ($vendor) = (pairkeys pairfirst { check_acl_no($d, $b) } %{ $config->{vendormap} }) || $d->vendor; @@ -93,6 +99,7 @@ register_worker({ phase => 'main' }, sub { push @{$routerdb->{$group}}, (sprintf "%s${delimiter}%s${delimiter}%s", $name, $vendor, ($d->get_column('old') ? 'down' : 'up')); + $routerunicity->{$group}->{$name} = 1; } foreach my $group (keys %$routerdb) {