App-Netdisco
view release on metacpan or search on metacpan
lib/App/Netdisco/Configuration.pm view on Meta::CPAN
# override from env for docker
if ($ENV{NETDISCO_DOMAIN}) {
if ($ENV{NETDISCO_DOMAIN} eq 'discover') {
delete $ENV{NETDISCO_DOMAIN};
if (! setting('domain_suffix')) {
info 'resolving domain name...';
config->{'domain_suffix'} = hostdomain;
}
}
else {
config->{'domain_suffix'} = $ENV{NETDISCO_DOMAIN};
}
}
# override SNMP bulkwalk from environment
config->{'bulkwalk_off'} = true
if (exists $ENV{NETDISCO_SNMP_BULKWALK_OFF} and $ENV{NETDISCO_SNMP_BULKWALK_OFF});
#Â check user's port_control_reasons
config->{'port_control_reasons'} =
config->{'port_control_reasons'} || config->{'system_port_control_reasons'};
# for managing database portctl_roles
config->{'portctl_by_role_shadow'}
= dclone (setting('portctl_by_role') || {});
# convert domain_suffix from scalar or list to regexp
config->{'domain_suffix'} = [setting('domain_suffix')]
if ref [] ne ref setting('domain_suffix');
if (scalar @{ setting('domain_suffix') }) {
my @suffixes = map { (ref qr// eq ref $_) ? $_ : quotemeta }
@{ setting('domain_suffix') };
my $buildref = '(?:'. (join '|', @suffixes) .')$';
config->{'domain_suffix'} = qr/$buildref/;
}
else {
config->{'domain_suffix'} = qr//;
}
#Â convert expire_devices from single to dict
if (q{} eq ref setting('expire_devices')) {
config->{'expire_devices'}
= { 'group:__ANY__' => setting('expire_devices') };
}
# convert tacacs from single to lists
if (ref {} eq ref setting('tacacs')
and exists setting('tacacs')->{'key'}) {
config->{'tacacs'} = [
Host => setting('tacacs')->{'server'},
Key => setting('tacacs')->{'key'} || setting('tacacs')->{'secret'},
Port => (setting('tacacs')->{'port'} || 'tacacs'),
Timeout => (setting('tacacs')->{'timeout'} || 15),
];
}
elsif (ref [] eq ref setting('tacacs')) {
my @newservers = ();
foreach my $server (@{ setting('tacacs') }) {
push @newservers, [
Host => $server->{'server'},
Key => $server->{'key'} || $server->{'secret'},
Port => ($server->{'port'} || 'tacacs'),
Timeout => ($server->{'timeout'} || 15),
];
}
config->{'tacacs'} = [ @newservers ];
}
# support unordered dictionaries as if they were a single item list
if (ref {} eq ref setting('device_identity')) {
config->{'device_identity'} = [ setting('device_identity') ];
}
else { config->{'device_identity'} ||= [] }
if (ref {} eq ref setting('macsuck_no_deviceport')) {
config->{'macsuck_no_deviceports'} = [ setting('macsuck_no_deviceport') ];
}
if (ref {} eq ref setting('macsuck_no_deviceports')) {
config->{'macsuck_no_deviceports'} = [ setting('macsuck_no_deviceports') ];
}
else { config->{'macsuck_no_deviceports'} ||= [] }
if (ref {} eq ref setting('hide_deviceports')) {
config->{'hide_deviceports'} = [ setting('hide_deviceports') ];
}
else { config->{'hide_deviceports'} ||= [] }
if (ref {} eq ref setting('ignore_deviceports')) {
config->{'ignore_deviceports'} = [ setting('ignore_deviceports') ];
}
else { config->{'ignore_deviceports'} ||= [] }
#Â copy old ignore_* into new settings
if (scalar @{ config->{'ignore_interfaces'} }) {
config->{'host_groups'}->{'__IGNORE_INTERFACES__'}
= [ map { ($_ !~ m/^port:/) ? "port:$_" : $_ } @{ config->{'ignore_interfaces'} } ];
}
if (scalar @{ config->{'ignore_interface_types'} }) {
config->{'host_groups'}->{'__IGNORE_INTERFACE_TYPES__'}
= [ map { ($_ !~ m/^type:/) ? "type:$_" : $_ } @{ config->{'ignore_interface_types'} } ];
}
if (scalar @{ config->{'ignore_notpresent_types'} }) {
config->{'host_groups'}->{'__NOTPRESENT_TYPES__'}
= [ map { ($_ !~ m/^type:/) ? "type:$_" : $_ } @{ config->{'ignore_notpresent_types'} } ];
}
# copy devices_no and devices_only into others
foreach my $name (qw/devices_no devices_only
discover_no macsuck_no arpnip_no nbtstat_no
discover_only macsuck_only arpnip_only nbtstat_only/) {
config->{$name} ||= [];
config->{$name} = [setting($name)] if ref [] ne ref setting($name);
}
foreach my $name (qw/discover_no macsuck_no arpnip_no nbtstat_no/) {
push @{setting($name)}, @{ setting('devices_no') };
}
foreach my $name (qw/discover_only macsuck_only arpnip_only nbtstat_only/) {
push @{setting($name)}, @{ setting('devices_only') };
}
# legacy config item names
( run in 0.532 second using v1.01-cache-2.11-cpan-39bf76dae61 )