Gus_Ferrer
Mar 13, 2012Nimbostratus
external monitor always marking nodes down
I am writing a script (which borrows heavily from some devcentral examples) that will ssh to a server and test for the presence of a file. If the file is there, the host should be marked down and therefore nothing is sent to stdout. If there is no file present, the server should be marked up, so "UP" is sent to stdout.
I've configured ssh to work without typing a password, and when I run the script manually from the command line it is behaving as expected. However, when I use it as an external monitor in my LTM, the monitored nodes are consistently marked down regardless of the presence or absence of the tested file. I'm guessing I'm confused about how the LTM is interpreting the exit codes but I can't figure out what is happening exactly. Here is the script, can anyone offer any advice on what I am doing wrong?
====
!/bin/bash
Log debug to local0.debug (/var/log/ltm)
Check if a variable named DEBUG exists from the monitor definition
This can be set using a monitor variable DEBUG=0 or 1
if [ -n "$DEBUG" ]
then
if [ $DEBUG -eq 1 ]; then echo "EAV `basename $0`: \$DEBUG: $DEBUG" | logger -p local0.debug;
fi
else
If the monitor config didn't specify debug, enable/disable it here
DEBUG=0
echo "EAV `basename $0`: \$DEBUG: $DEBUG" | logger -p local0.debug
fi
Remove IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)
NOTE - $1 variable is IP address, and it is set automatically by the LTM.
IP=`echo $1 | sed 's/::ffff://'`
Check if there is a prior instance of the monitor running
pidfile="/var/run/`basename $0`.$IP.pid"
if [ -f $pidfile ]
then
kill -9 `cat $pidfile` > /dev/null 2>&1
echo "EAV `basename $0`: exceeded monitor interval, needed to kill ${IP} with PID `cat $pidfile`" | logger -p local0.error
fi
Add the current PID to the pidfile
echo "$$" > $pidfile
Debug
if [ $DEBUG -eq 1 ]
then
Customize the log statement here if you want to log the command run or the output
echo "EAV `basename $0`: Running ssh monitor for ${IP} using custom command" | logger -p local0.debug
fi
Send the request request and check the response
ssh -i /root/healthcheck/.ssh/healthcheck_id_rsa -l healthcheck $1 "test ! -f /tmp/server_down.txt" > /dev/null 2>$1
If the file is there, node will be marked down.
If file is missing, node will be marked up.
if [ $? == 0 ]
then
echo "UP"
if [ $DEBUG -eq 1 ]; then echo "EAV `basename $0`: Succeeded for ${IP}:$2" | logger -p local0.debug; fi
else
if [ $DEBUG -eq 1 ]; then echo "EAV `basename $0`: Failed for ${IP}:$2" | logger -p local0.debug; fi
fi
rm -f $pidfile
====
Thanks.