failover monitoring

Sebastien J. Gross sjg at easynet.fr
Mon Jul 5 11:20:50 CEST 2004


On Sat, Jul 03, 2004 at 08:41:36PM -0500, adamemery at sbcglobal.net wrote:
> Does anybody have an example of the script needed for failover
> monitoring.  The docs only say to create a cron job that runs a script
> blah, blah, blah. 

I use this one on the slave host:

#!/bin/sh

DELAY=1
HOST=[SET MASTER HOSTNAME HERE]
NRPE=/usr/lib/nagios/plugins/check_nrpe
CMD_FILE=/var/log/nagios/rw/nagios.cmd
MYSQL_DEFAULTS_FILE=/etc/nagios/nagios.my.cnf
CHECK_STATUS=/var/state/nagios/$HOST.status


if ! test -d $(dirname $CHECK_STATUS); then
  mkdir -p $(dirname $CHECK_STATUS)
fi

while true; do

  $NRPE -H $HOST $* -c check_nagios > /dev/null 2>&1
  n=$?
  mysql --defaults-file=$MYSQL_DEFAULTS_FILE -e "STATUS" -h $HOST >
/dev/null 2>&1
  m=$?
  echo "nagios=$n mysql=$m" >$CHECK_STATUS
  datetime=$(date +%s)
  if test -p $CMD_FILE; then
    if test $n -eq 0 -a $m -eq 0; then 
      echo "Nagios is running" >> $CHECK_STATUS
      echo "[$datetime] DISABLE_NOTIFICATIONS;$datetime" >> $CMD_FILE
      echo "[$datetime] STOP_EXECUTING_SVC_CHECKS" >> $CMD_FILE
    else
      echo "Nagios is NOT running" >> $CHECK_STATUS
      echo "[$datetime] ENABLE_NOTIFICATIONS;$datetime" >> $CMD_FILE
      echo "[$datetime] START_EXECUTING_SVC_CHECKS" >> $CMD_FILE
    fi
  fi
  datetime=`date +%s`
  sleep $DELAY
done


It checks both nagios & mysql on the primary server and allows (or
disallows) checks on slave if needed (either if nagios or mysql is down
on slave).

-- 
Sebastien J. Gross


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list