add by_hostname config option to netdisco-rancid-export
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
[ENHANCEMENTS]
|
[ENHANCEMENTS]
|
||||||
|
|
||||||
* portctl_nameonly to limit port control to name only (F. Schiavarelli)
|
* portctl_nameonly to limit port control to name only (F. Schiavarelli)
|
||||||
|
* add by_hostname config option to netdisco-rancid-export
|
||||||
|
|
||||||
[BUG FIXES]
|
[BUG FIXES]
|
||||||
|
|
||||||
|
|||||||
@@ -43,15 +43,22 @@ use Dancer::Plugin::DBIC 'schema';
|
|||||||
use App::Netdisco::Util::Permission ':all';
|
use App::Netdisco::Util::Permission ':all';
|
||||||
|
|
||||||
my $settings = setting( 'rancid' );
|
my $settings = setting( 'rancid' );
|
||||||
|
my $domain_suffix = setting( 'domain_suffix' );
|
||||||
my $delimiter = $settings->{ 'delimiter' } || ':';
|
my $delimiter = $settings->{ 'delimiter' } || ':';
|
||||||
my $down_age = $settings->{ 'down_age' } || '1 day';
|
my $down_age = $settings->{ 'down_age' } || '1 day';
|
||||||
my $rancidhome = $settings->{ 'rancid_home' } || '/var/lib/rancid';
|
my $rancidhome = $settings->{ 'rancid_home' } || '/var/lib/rancid';
|
||||||
my $config_vendormap = $settings->{ 'vendormap' } || {};
|
my $config_vendormap = $settings->{ 'vendormap' } || {};
|
||||||
|
|
||||||
my $by_ip = {};
|
my $by_ip = {};
|
||||||
foreach my $g (@{$settings->{ 'by_ip' }}) {
|
foreach my $g (@{$settings->{ 'by_ip' }}) {
|
||||||
$by_ip->{$g} = 1;
|
$by_ip->{$g} = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $by_hostname = {};
|
||||||
|
foreach my $g (@{$settings->{ 'by_hostname' }}) {
|
||||||
|
$by_hostname->{$g} = 1;
|
||||||
|
}
|
||||||
|
|
||||||
my @devices = schema('netdisco')->resultset('Device')->search({},
|
my @devices = schema('netdisco')->resultset('Device')->search({},
|
||||||
{
|
{
|
||||||
'+columns' => {
|
'+columns' => {
|
||||||
@@ -92,13 +99,16 @@ foreach my $group (keys %$list) {
|
|||||||
$vendor = $VENDORMAP{$vendormodel} || $VENDORMAP{$vendor};
|
$vendor = $VENDORMAP{$vendormodel} || $VENDORMAP{$vendor};
|
||||||
}
|
}
|
||||||
if ( $config_vendormap->{$vendor} or $config_vendormap->{$vendormodel} ) {
|
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}) {
|
if ($by_ip->{$group}) {
|
||||||
$name = $dev->ip;
|
$name = $dev->ip;
|
||||||
} else {
|
} else {
|
||||||
$name = ($dev->dns || $dev->name);
|
$name = ($dev->dns || $dev->name);
|
||||||
}
|
}
|
||||||
|
if ($by_hostname->{$group}) {
|
||||||
|
$name =~ s/$domain_suffix$//;
|
||||||
|
}
|
||||||
printf ROUTER "%s$delimiter%s$delimiter%s\n", $name, $vendor,
|
printf ROUTER "%s$delimiter%s$delimiter%s\n", $name, $vendor,
|
||||||
$dev->get_column( 'old' ) ? "down" : "up";
|
$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'
|
down_age: '1 day'
|
||||||
delimiter: ':'
|
delimiter: ':'
|
||||||
by_ip: [ other ]
|
by_ip: [ other ]
|
||||||
|
by_hostname: [ other2 ]
|
||||||
groups:
|
groups:
|
||||||
switch: [ 'name:.*[Ss][Ww].*' ]
|
switch: [ 'name:.*[Ss][Ww].*' ]
|
||||||
rtr: [ 'name:[rR]tr.*' ]
|
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
|
List of RANCID Groups which will have Device IPs written to the RANCID
|
||||||
configuration file, instead of DNS or SNMP host names.
|
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
|
=head1 SEE ALSO
|
||||||
|
|
||||||
=over 4
|
=over 4
|
||||||
|
|||||||
Reference in New Issue
Block a user