[rancid] Replace commands for specific hosts

Valeriy Simonov simonov at gmail.com
Mon Sep 20 08:37:40 UTC 2010


Hello!

Rancid is great, but there are some situations, when some hosts make too
much noise and we can't do anything with that. For example, some Cisco
device update their flash too frequent, or some scripts make changes to some
ACLs several times a hour. It's too annoying to receive that changes every
hour, even if that information has no value. The solution could be simple:
just avoid some commands or replace them. I've decided to make a patch for
that.

First, we should add some parameters in rancid.conf file:
HOST_REPLACE_CMD=""; export HOST_REPLACE_CMD
HOST_REPLACE_CMD="$HOST_REPLACE_CMD 10.1.1.1, 'show flash', 'show flash |
exclude bootflash',"; export HOST_REPLACE_CMD
HOST_REPLACE_CMD="$HOST_REPLACE_CMD 10.2.2.2, 'show flash', 'show flash |
exclude bootflash',"; export HOST_REPLACE_CMD
HOST_REPLACE_CMD="$HOST_REPLACE_CMD 10.3.3.3, 'more system:running-config',
'more system:running-config | section exclude standard ist$',"; export
HOST_REPLACE_CMD

That parameters are telling script to replace 'show flash' command for hosts
10.1.1.1 and 10.2.2.2 with 'show flash | exclude bootflash' to scrub
bootflash info completely, and replace 'more system:running-config' for host
10.3.3.3 with 'more system:running-config | section exclude standard ist$'
to exclude standard access-list with name ist from the resulting file. You
should use that replacements with *certainty that you will not lose some
valuable information.*
*
*
*Number of replacements is not limited, just be sure not to skip a comma
after last quote in each line (do not place comma after a double quote!).*
*
*
*Next, we should apply a patch to rancid file with the name, ahem, 'rancid':
*
patchpatchpatchpatchpatchpatchpatchpatchpatchpatch

--- rancid.orig 2010-08-05 11:17:24.000000000 +0600
+++ rancid 2010-09-20 12:50:18.000000000 +0600
@@ -1929,6 +1929,22 @@
  {'show running-config' => 'WriteTerm'},
  {'write term' => 'WriteTerm'},
 );
+# Replace commands if host matches
+$host_replace_cmd = $ENV{HOST_REPLACE_CMD};
+ at commandreplace = ();
+push(@commandreplace, $+) while $host_replace_cmd =~ m{'(.*?)'|(\S+),\s*}g;
+$cr_length = $#commandreplace;
+for($i = 0; $i <= $cr_length; $i = $i + 3) {
+ my $cr_host = $commandreplace[$i];
+ if ($host eq $cr_host) {
+ my $cr_cmdsearch = $commandreplace[$i + 1];
+ my $cr_cmdreplace = $commandreplace[$i + 2];
+ my ($index) = grep { defined $commandtable[$_]{$cr_cmdsearch} }
0..$#commandtable;
+ my $cr_function = $commandtable[$index]{$cr_cmdsearch};
+ splice(@commandtable, $index, 1, {$cr_cmdreplace => $cr_function});
+ }
+}
+
 # Use an array to preserve the order of the commands and a hash for mapping
 # commands to the subroutine and track commands that have been completed.
 @commands = map(keys(%$_), @commandtable);

patchpatchpatchpatchpatchpatchpatchpatchpatchpatch

Check that everything's working fine by running "rancid -d hostname" and
checking it's output. I would be glad if this patch or some similar logic
will be in the next release of rancid.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20100920/4ec30ac5/attachment.html>


More information about the Rancid-discuss mailing list