A script to check cacti
January 9, 2013 Leave a comment
A simple script to check whether cacti works well.
#!/bin/bash if [ $# -lt 2 ]; then cat <<EOF Check cacti log usage: check_cacti.sh <CACTI_HOME> examples: check_cacti.sh /export/home/cacti 30 #check last 30 lines in cacti log EOF exit 1 fi # arguments CACTI_HOME="$1" lines_to_check="$2" # configuration MAIL_TO="alexzeng@wordpress.com" CACTI_LOG="$CACTI_HOME/log/cacti.log" CHECK_LOG="$CACTI_HOME/log/check_cacti.log" echo "`date` : Start" > $CHECK_LOG echo "" >> $CHECK_LOG #check if the logfile get updated current=`date +%s` last_modified=`stat -c "%Y" $CACTI_LOG` if [ $(($current-$last_modified)) -gt 3600 ]; then title="CACTI log didn't get updated in last hour"; ls -lt $CACTI_LOG >> $CHECK_LOG fi #check warning or error msg in log, only if cacti log is updated if [ "alex$title" = "alex" ] ; then warining=`tail -$lines_to_check $CACTI_LOG | grep -i -e warning -e error` if [ "alex$warining" = "alex" ] ; then echo "No warning or error msg" >> $CHECK_LOG else title="found warning/error in $CACTI_LOG" tail -$lines_to_check $CACTI_LOG | grep -i -e warning -e error >> $CHECK_LOG fi fi echo "" >> $CHECK_LOG echo "`date` : End" >> $CHECK_LOG #send mail if [ "alex$title" != "alex" ] ; then title="$title at `hostname`" mailx -s "$title" $MAIL_TO < $CHECK_LOG fi
Add a cron job to check cacti every hour.
#check cacti 0 * * * * /export/home/cacti/cli/check_cacti.sh /export/home/cacti 30