diff --git a/lib/App/Netdisco/Core/Discover.pm b/lib/App/Netdisco/Core/Discover.pm index 99d5e8ff..5ee71e92 100644 --- a/lib/App/Netdisco/Core/Discover.pm +++ b/lib/App/Netdisco/Core/Discover.pm @@ -50,15 +50,31 @@ the IP and hostname in the device object for the canonical IP. sub set_canonical_ip { my ($device, $snmp) = @_; - my $old_ip = $device->ip; - my $new_ip = $old_ip; - my $revname = ipv4_from_hostname($snmp->name); + my $old_ip = $device->ip; + my $new_ip = $old_ip; + my $revofname = ipv4_from_hostname($snmp->name); - if (setting('reverse_sysname') and $revname) { - $new_ip = $revname; + if (setting('reverse_sysname') and $revofname) { + $new_ip = $revofname; } - if (setting('device_identity')) { + if (ref {} eq ref setting('device_identity')) { + my $idmap = setting('device_identity') || {}; + my $devips = $device->device_ips->order_by('alias'); + + ALIAS: while (my $alias = $devips->next) { + foreach my $this (keys %$idmap) { + $anded_this = [(ref $this ? @$this : $this), 'op:and']; + + if (check_acl($device, $anded_this) + and check_acl($alias, $idmap->{$this}) + and $alias->alias ne $old_ip) { + + $new_ip = $alias->alias; + last ALIAS; + } + } + } } return if $new_ip eq $old_ip; diff --git a/lib/App/Netdisco/Manual/ReleaseNotes.pod b/lib/App/Netdisco/Manual/ReleaseNotes.pod index 1374e2d7..f16e1d72 100644 --- a/lib/App/Netdisco/Manual/ReleaseNotes.pod +++ b/lib/App/Netdisco/Manual/ReleaseNotes.pod @@ -95,16 +95,6 @@ you can often influence this through device configuration (LLDP advertise...). =cut -# Via configuration there are two further settings. C tells -# Netdisco to take the SNMP System Name and do a reverse DNS lookup for the -# canonical IP. The new configuration setting C allows you to -# set rules for picking the canonical interface from a device based on any of -# its properties (model, vendor, OS, OS version, etc). -# -# Typical use would be either to leave Netdisco to use the discovered IP, or use -# C to control the canonical IP/name for classes of device -# based on model/vendor, etc. - =head1 2.032000 =head2 General Notices diff --git a/share/config.yml b/share/config.yml index 42a2f8d7..5130aedd 100644 --- a/share/config.yml +++ b/share/config.yml @@ -116,6 +116,7 @@ login_logo: "" # mibhome is discovered from environment # mibdirs defaults to contents of mibhome host_groups: {} +device_identity: {} community: ['public'] community_rw: ['private'] snmp_auth: []