rancid: mail filenames only, set max rounds

Morty Abzug morty at sled.gsfc.nasa.gov
Tue Apr 26 04:06:55 UTC 2005


On Fri, Apr 22, 2005 at 02:12:39PM -0700, john heasley wrote:
> [ trying this again; first one bounced from verisign ]
> 
> Thu, Apr 21, 2005 at 10:25:39AM -0700, john heasley:
> > Wed, Apr 20, 2005 at 09:06:33PM -0400, Mordechai T. Abzug:
> > > 
> > > The attached patch:
> > > 
> > > - adds a "MAIL_FILENAME_ONLY" tunable to control whether entire diffs
> > >   are mailed as per the default, or only the filename is mailed.
> > 
> > This is interesting.  Perhaps it would be more interesting to generate the
> > cvs command necessary to generate the diff?  eg:
> > 	cvs diff -r 1.1 -r 1.2 hostname
> > OR
> > 	cvs diff -r 1.1 -r 1.2 group/configs/hostname

Hmm.  I would prefer to just use the old version:

cvs diff -r1.1 whatever/configs/hostname

This is fairly necessary, since the next CVS version hasn't been
assigned yet at this point, and guessing is perilous.

Done, in attached patch.

> > > - adds a "MAX_ROUNDS" tunable to control the maximum number of
> > >   rounds/passes.
> > 
> > Added.  I changed it just a little to ensure the floor of 1 itteration.
> > Thanks!

Thank you!

The attached patch also includes a few minor tweaks to deal with
Solaris systems that don't have GNU diff installed.  Ie. do a straight
diff instead of diff -c -4.  In the contexts involved, the context
options don't matter.

[Patch also includes the MAX_ROUNDS patch that you've already
accepted; don't know what your preferences are on patch submission.]

- Morty
-------------- next part --------------
diff -cr rancid-2.3.1/bin/control_rancid.in rancid-2.3.1-local-p2/bin/control_rancid.in
*** rancid-2.3.1/bin/control_rancid.in	Fri Mar 12 23:13:09 2004
--- rancid-2.3.1-local-p2/bin/control_rancid.in	Tue Apr 26 02:50:05 2005
***************
*** 138,152 ****
  	sort -u > routers.db
  cut -d: -f1,2 routers.db > routers.all.new
  if [ ! -f routers.all ] ; then touch routers.all; fi
! @DIFF_CMD@ routers.all routers.all.new > /dev/null 2>&1; RALL=$?
  @PERLV@ -F: -ane '{($F[0] =~ tr at A-Z@a-z@,print $_)
      if ($F[2] !~ /^up$/i);}' routers.db > routers.down.new
  if [ ! -f routers.down ] ; then touch routers.down; fi
! @DIFF_CMD@ routers.down routers.down.new > /dev/null 2>&1; RDOWN=$?
  @PERLV@ -F: -ane '{($F[0] =~ tr at A-Z@a-z@,print "$F[0]:$F[1]\n")
      if ($F[2] =~ /^up$/i);}' routers.db > routers.up.new
  if [ ! -f routers.up ] ; then touch routers.up; fi
! @DIFF_CMD@ routers.up routers.up.new > /dev/null 2>&1; RUP=$?
  
  if [ $RALL -ne 0 -o $RDOWN -ne 0 -o $RUP -ne 0 ]
  then
--- 138,152 ----
  	sort -u > routers.db
  cut -d: -f1,2 routers.db > routers.all.new
  if [ ! -f routers.all ] ; then touch routers.all; fi
! @DIFF@ routers.all routers.all.new > /dev/null 2>&1; RALL=$?
  @PERLV@ -F: -ane '{($F[0] =~ tr at A-Z@a-z@,print $_)
      if ($F[2] !~ /^up$/i);}' routers.db > routers.down.new
  if [ ! -f routers.down ] ; then touch routers.down; fi
! @DIFF@ routers.down routers.down.new > /dev/null 2>&1; RDOWN=$?
  @PERLV@ -F: -ane '{($F[0] =~ tr at A-Z@a-z@,print "$F[0]:$F[1]\n")
      if ($F[2] =~ /^up$/i);}' routers.db > routers.up.new
  if [ ! -f routers.up ] ; then touch routers.up; fi
! @DIFF@ routers.up routers.up.new > /dev/null 2>&1; RUP=$?
  
  if [ $RALL -ne 0 -o $RDOWN -ne 0 -o $RUP -ne 0 ]
  then
***************
*** 308,315 ****
  
  # This section will generate a list of missed routers
  # and try to grab them again.  It will run through
! # $pass times.
! pass=4
  round=1
  if [ -f $DIR/routers.up.missed ]; then
      rm -f $DIR/routers.up.missed
--- 308,315 ----
  
  # This section will generate a list of missed routers
  # and try to grab them again.  It will run through
! # $pass times; tune with MAX_ROUNDS, default 4
! pass=${MAX_ROUNDS:=4}
  round=1
  if [ -f $DIR/routers.up.missed ]; then
      rm -f $DIR/routers.up.missed
***************
*** 369,376 ****
  # Diff the directory and then checkin.
  trap 'rm -fr $TMP $TMP.diff $DIR/routers.single;' 1 2 15
  cd $DIR
! cvs -f @DIFF_CMD@ | sed -e '/^RCS file: /d' -e '/^--- /d' \
! 	-e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
  
  if [ $alt_mailrcpt -eq 1 ] ; then
      subject="router config diffs - courtesy of $mailrcpt"
--- 369,387 ----
  # Diff the directory and then checkin.
  trap 'rm -fr $TMP $TMP.diff $DIR/routers.single;' 1 2 15
  cd $DIR
! mail_filename_only=${MAIL_FILENAME_ONLY:=0}
! hostname=`hostname`
! if [ "$mail_filename_only" = "0" ]; then
! 	cvs -f @DIFF_CMD@ | sed -e '/^RCS file: /d' -e '/^--- /d' \
! 		-e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
! else 
! 	cvs -f @DIFF_CMD@ | \
!                 sed -ne 's,^Index:,Config changed:,p' \
!                   -e "s/^======.*/  For recent changes, run on $hostname:/p" \
!                   -e 's,^RCS file: \(.*\)/CVS\(/.*/\).*,    cd \1\2 \&\&,p' \
!                   -e 's,^diff,    cvs diff,p' \
!                 > $TMP.diff  
! fi
  
  if [ $alt_mailrcpt -eq 1 ] ; then
      subject="router config diffs - courtesy of $mailrcpt"
diff -cr rancid-2.3.1/etc/rancid.conf.sample.in rancid-2.3.1-local-p2/etc/rancid.conf.sample.in
*** rancid-2.3.1/etc/rancid.conf.sample.in	Sat Mar 13 00:17:50 2004
--- rancid-2.3.1-local-p2/etc/rancid.conf.sample.in	Thu Apr 21 01:54:11 2005
***************
*** 49,54 ****
--- 49,57 ----
  # The number of devices to collect simultaneously.
  #PAR_COUNT=5; export PAR_COUNT
  #
+ # How many times should we try to reach devices?  Minimum: one.
+ #MAX_ROUNDS=4; export MAX_ROUNDS
+ #
  # list of rancid groups
  #LIST_OF_GROUPS="sl joebobisp"
  # more groups...
***************
*** 65,67 ****
--- 68,74 ----
  # included, as this is simply appended to the usual recipients.  It is NOT
  # appended to recipients specified in rancid-run's -m option.
  #MAILDOMAIN="@example.com"; export MAILDOMAIN
+ #
+ # if you don't want to actually email the diffs, just the names of the files
+ # that changed, set the below to 1
+ #MAIL_FILENAME_ONLY=0; export MAIL_FILENAME_ONLY
diff -cr rancid-2.3.1/man/rancid.conf.5.in rancid-2.3.1-local-p2/man/rancid.conf.5.in
*** rancid-2.3.1/man/rancid.conf.5.in	Fri Mar 12 23:13:09 2004
--- rancid-2.3.1-local-p2/man/rancid.conf.5.in	Thu Apr 21 01:54:11 2005
***************
*** 115,120 ****
--- 115,126 ----
  Default: $BASEDIR/logs
  .\"
  .TP
+ .B MAIL_FILENAME_ONLY
+ Control whether diff bodies are mailed or filenames that have changed
+ are mailed.  The default, 0, is diff bodies.  Set to any other value for 
+ filenames only.
+ .\"
+ .TP
  .B MAILDOMAIN
  Define the domain part of addresses for administrative and diff e-mail.
  The value of this variable is simply appended to the normal mail addresses.
***************
*** 123,128 ****
--- 129,139 ----
  had been set to "@example.com".
  .\"
  .TP
+ .B MAX_ROUNDS
+ Defines how many times rancid should use to reach devices.  The minimum is 
+ 1.  The default is 4.
+ .\"
+ .TP
  .B NOCOMMSTR
  If set,
  .IR rancid (1)


More information about the Rancid-discuss mailing list