Letendart
Mar 07, 2018Nimbostratus
Monitor always show nodes up even if down ...
Hi all, I'm wondering what's wrong in the external monitor I have created. Target is to monitor NTP server status.
I get the correct status (UP, DOWN) when I run the batch via SSH on the F5 VM
It DOESN'T run via the MONITOR ... status is always up and I get the message "exceeded monitor interval" in the LTM
I spent hours on it without finding the error ... Sure I miss something ... help ! ... please
thanks
Here is the code :
!/bin/bash
target is to monitor the NTP appliances and to log their status
Log debug to local0.debug (/var/log/ltm)?
Check if a variable named DEBUG exists from the monitor definition
if ! [ -n "$DEBUG" ]
then
If the monitor config didn't specify debug, enable/disable it here
DEBUG=1
fi
Remove IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)
IP=`echo $1 | sed 's/::ffff://'`
Save the port for use in the shell command
PORT=$2
Check if there is a prior instance of the monitor running
pidfile="/var/run/`basename $0`.$IP.$PORT.pid"
if [ -f $pidfile ]
then
kill -9 `cat $pidfile` > /dev/null 2>&1
echo "NTP server $IP `basename $0`: exceeded monitor interval, needed to kill ${IP}:${PORT} with PID `cat $pidfile`" | logger -p local0.error
fi
Add the current PID to the pidfile
echo "$$" > $pidfile
NTP status
command="ntpdate -q $IP"
eval "$command 2>&1 > /dev/null"
if the NTP server is reachable
if [ $? -eq 0 ]
then
Extract the offset (before the floating point)
result=$(eval $command)
arr=($result)
offset=${arr[5]}
declare -i offset=${offset%%.*,}
if offset < 1 sec then node is UP
if [ $offset -gt -1 ] && [ $offset -le 1 ]
then
rm -f $pidfile
echo "UP"
else
rm -f $pidfile
if [ $DEBUG -eq 1 ]; then echo "NTP server $IP out of sync offset=$offset" | logger -p local0.debug; fi
fi
else
rm -f $pidfile
if [ $DEBUG -eq 1 ]; then echo "NTP server $IP not reachable" | logger -p local0.debug; fi
fi