add by_hostname config option to netdisco-rancid-export

This commit is contained in:
Oliver Gorwits
2014-07-13 18:24:56 +01:00
parent 13de616e35
commit e06f1b3437
2 changed files with 19 additions and 1 deletions

View File

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

View File

@@ -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<by_hostname>
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<domain_suffix> configuration item from the FQDN.
=head1 SEE ALSO
=over 4