A simple nagios/bash script to check if a RedHat/CentOS cluster has failedover.It uses the output from the clustat command.
The usage is simple the script name and service, example:
check_usage IO_Service
It has been tested only with a 2 node clusters running RedHat.

#!/bin/bash
# Script to check if RedHat cluster has failed over
# Felipe Ferreira Jan 2013
# ver 1.0
if [ ! $# == 1 ]; then
echo "Usage check_cluster <cluster_service_name>"
exit 2
fi;
clu_srv=$1
service1=`clustat|grep $clu_srv| awk {'print $1'}`
host1=`clustat|grep $1| awk {'print $2'}`
tmpfile="/tmp/check_cluster_${clu_srv}.log"
tmpfile2="/tmp/check_cluster2_${clu_srv}.log"
echo $service1 $host1 > $tmpfile2
DIFF=`diff $tmpfile $tmpfile2`
#limpa output
DIFF=`echo $DIFF |cut -d ">" -f2`
host1=`echo $host1 |cut -d "-" -f1`
service1=`echo $service1 |cut -d":" -f2`
mv $tmpfile2 $tmpfile
if [ ! -z "${DIFF}" ]; then
echo "CRITICAL - Cluster $clu_srv fez failover ao $host1"
exit 3
else
echo "OK - Cluster $clu_srv continua no mesmo servidor $host1"
exit 0
fi;
Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *