#!/usr/bin/sh # Function to send a RANCID log to syslog LogIt() { # This routine will take a single RANCID log file, condense it, and # send it to syslog. # # Parameters # $1 - The name of the RANCID log file to process # # Build temp files ERR=$(mktemp) ADD=$(mktemp) UPD=$(mktemp) LOG=$(mktemp) # Get the name of the rancid group GRP=$(expr match $1 '.*\/\([a-z]*\)\.') # Get new devices grep "Added " $1 > $ADD # Get updated devices grep "Checking in " $1 > $UPD # Get and reduce errors to a single line per device grep "clogin error" $1 | sort | uniq -c > $ERR # Compute some statistics on added, updated and errors ADDCNT=$(wc -l < $ADD) UPDCNT=$(wc -l < $UPD) ERRCNT=$(wc -l < $ERR) # Create a file of the lines to send to syslog grep "starting:" $1 > $LOG cat $ADD >> $LOG cat $UPD >> $LOG cat $ERR >> $LOG echo "Added=$ADDCNT Updated=$UPDCNT Errors=$ERRCNT" >> $LOG grep "ending:" $1 >> $LOG # Send the file to syslog logger -s -f $LOG -p local0.info -t "rancid-run Group=$GRP " # Clean up temp files rm $LOG $UPD $ADD $ERR } # ===== Main routine # Run default ENVFILE to get the LOGDIR. ENVFILE="/etc/rancid/rancid.conf" . $ENVFILE # Test/set a lock file LOCKFILE="/rancid/locks/processing" if [ -e $LOCKFILE ] then echo "Lock file $LOCKFILE exists." exit fi touch $LOCKFILE # Run RANCID echo "Running rancid-run" /usr/libexec/rancid/rancid-run # Because RANCID does not syslog directly, we will need to convert # the RANCID logs to syslog events. And, we don't know the name of # the log files. But, we do know the directory that the log files are # stored in. We also know that they will be newer than the date/time # on our lock file. So, we use 'find' to find all log files in the # LOGDIR newer than the lock file, and process them one at a time. LOGS=$(find $LOGDIR -type f -newer $LOCKFILE) for FILE in $LOGS do LogIt $FILE done # Now, remove the lock file rm $LOCKFILE