diff --git a/Netdisco/Changes b/Netdisco/Changes index 8f199e4d..b01d5464 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -3,6 +3,7 @@ [ENHANCEMENTS] * portctl_nameonly to limit port control to name only (F. Schiavarelli) + * add by_hostname config option to netdisco-rancid-export [BUG FIXES] diff --git a/Netdisco/bin/netdisco-rancid-export b/Netdisco/bin/netdisco-rancid-export index 578d6c91..cf784fc7 100755 --- a/Netdisco/bin/netdisco-rancid-export +++ b/Netdisco/bin/netdisco-rancid-export @@ -43,15 +43,22 @@ use Dancer::Plugin::DBIC 'schema'; use App::Netdisco::Util::Permission ':all'; my $settings = setting( 'rancid' ); +my $domain_suffix = setting( 'domain_suffix' ); my $delimiter = $settings->{ 'delimiter' } || ':'; my $down_age = $settings->{ 'down_age' } || '1 day'; my $rancidhome = $settings->{ 'rancid_home' } || '/var/lib/rancid'; my $config_vendormap = $settings->{ 'vendormap' } || {}; + my $by_ip = {}; foreach my $g (@{$settings->{ 'by_ip' }}) { $by_ip->{$g} = 1; } +my $by_hostname = {}; +foreach my $g (@{$settings->{ 'by_hostname' }}) { + $by_hostname->{$g} = 1; +} + my @devices = schema('netdisco')->resultset('Device')->search({}, { '+columns' => { @@ -92,13 +99,16 @@ foreach my $group (keys %$list) { $vendor = $VENDORMAP{$vendormodel} || $VENDORMAP{$vendor}; } if ( $config_vendormap->{$vendor} or $config_vendormap->{$vendormodel} ) { - $vendor = $config_vendormap{$vendormodel} || $config_vendormap{$vendor}; + $vendor = $config_vendormap->{$vendormodel} || $config_vendormap->{$vendor}; } if ($by_ip->{$group}) { $name = $dev->ip; } else { $name = ($dev->dns || $dev->name); } + if ($by_hostname->{$group}) { + $name =~ s/$domain_suffix$//; + } printf ROUTER "%s$delimiter%s$delimiter%s\n", $name, $vendor, $dev->get_column( 'old' ) ? "down" : "up"; } @@ -119,6 +129,7 @@ This script requires some configuration to be added to your Netdisco down_age: '1 day' delimiter: ':' by_ip: [ other ] + by_hostname: [ other2 ] groups: switch: [ 'name:.*[Ss][Ww].*' ] rtr: [ 'name:[rR]tr.*' ] @@ -172,6 +183,12 @@ Netdisco's "C<*_only>" settings, and accepts IP, prefix, device property. List of RANCID Groups which will have Device IPs written to the RANCID configuration file, instead of DNS or SNMP host names. +=head2 C + +List of RANCID Groups which will have Device Hostname written to the RANCID +configuration file, instead of FQDN. This is done simply by stripping the +C configuration item from the FQDN. + =head1 SEE ALSO =over 4