During this implementation and fine tuning (NetDB version 1.12), I stumbled on an undocumented option where the PERL script can call a function to collect the device configuration. This is done by invoking the equivalent "show configuration" for every vendor/product. I modified this a bit which included my contribution for HP Comware scraper which can also extract the device configuration via "display current-configuration".
opt/netdbscraper/comwarescraper.pl -conf /etc/netdb/netdb.conf -v -debug 5 -d \
hpcomwareswitch.company.com,nomac,noarp,dobackup,forcessh,devtype=comware
sub getDeviceConfig {
my @configuration;
my @output;
# Set config_directory where the retrieved configuration is stored
my $configdir = "$rootdir/config";
my $sanity_check;
my $devicename = $$devref{host};
my $datestring = strftime "%F-%H-%M", localtime;
if ( ! $optConfFile ) {
$optConfFile = "$configdir/$$devref{host}.cfg";
}
# Captures configuration from device
@output = SSHCommand( $session, "display current-configuration" );
# Results returned in one scalar, split out
@output = split( /\r/, $output[0] );
# Check for "sysname" in output which is the device hostname
foreach my $line ( @output ) {
if ( $line =~ /sysname/ ) { $sanity_check = 1; }
}
# Sanity check if managed to get configuration
if ( !$sanity_check ) {
print STDERR "$scriptName($PID): |ERROR|: No configuration received from $$devref{host} (use netdbctl -debug 2 for more info)\n";
@configuration = undef;
} else {
print "$scriptName($PID): Display the Device Configuration on $$devref{fqdn}\n" if $DEBUG>4;
foreach my $line ( @output ) {
$line =~ s/\n//g;
push( @configuration, "$line" ); # save for writing to file
}
# Check for results, output error if no data found
if ( !$configuration[0] ) {
print STDERR "$scriptName($PID): |ERROR|: No configuration received from $$devref{host} (use netdbctl -debug 2 for more info)\n";
print "DEBUG: Bad Configuration Data Received: @output" if $DEBUG>1;
return 0;
}
}
return \@configuration;
}
From this NetDb scraper script, I was able to store all network devices configuration into a separate directory. Then I need a revision control system to check/compare these configuration files. I settled with Subversion for simplicy and configured BASH script running via crontab which checks all these configuration files. You need to create an svn working copy before proceeding here.
# to be inserted in /etc/crontab
# Run SVN update to check for new configuration
*/10 * * * * root /opt/scripts/svnupdatecfg.sh
For the Subversion web interfaces, I chose WebDAV for simplicity and ViewVC for functionality. I also added email functionality using libsvn-notify-perl Debian package whenever changes are detected on the configuration. This is inserted in the post commit hooks as instructed here.
#!/bin/sh
# located in <svn_worrking_directory>/hooks/post-commit
REPOS="$1"
REV="$2"
SVNNOFITY="/usr/bin/svnnotify"
VIEWVCURL="https://svnserver.company.com/viewvc/configurations?view=revision&revision=%s"
$SVNNOFITY --repos-path "$REPOS" --revision "$REV" \
--subject-prefix 'Device Configuration' --subject-cx --with-diff --viewcvs-url $VIEWVCURL \
--to [email protected] --from [email protected] | logger
I hope this helps other trying to explore the usage of NetDB and Subversion in device configuration management. Let me know if things are not clear and I will update this post.
In my next testing, I will convert this method using Git :)