Hi!
There's no need to save the node ip since you're only checking the pools. Also, the removal of the pid file should be placed before the "echo up" as the "up" string makes the ltm exit the script.
Here's a version that worked for me at least. Change the pool names with those of your own.
!/bin/sh
Name of the pidfile
pidfile="/var/run/$MONITOR_NAME.$1..$2.pid"
Send signal to the process group to kill our former self and any children
as external monitors are run with SIGHUP blocked
if [ -f $pidfile ]
then
kill -9 -`cat $pidfile` > /dev/null 2>&1
fi
echo "$$" > $pidfile
pool1=$(tmsh show ltm pool SorryPool field-fmt | grep -o offline)
pool2=$(tmsh show ltm pool PajoIIS-8080-8081_pool field-fmt | grep -o offline)
if [ -z $pool1 ] && [ -z $pool2 ];
then
rm -f $pidfile
echo "up"
fi
You might want to change the check from offline to accomodate the scenario where the members are disabled as well?
!/bin/sh
Name of the pidfile
pidfile="/var/run/$MONITOR_NAME.$1..$2.pid"
Send signal to the process group to kill our former self and any children
as external monitors are run with SIGHUP blocked
if [ -f $pidfile ]
then
kill -9 -`cat $pidfile` > /dev/null 2>&1
fi
echo "$$" > $pidfile
status=0
tmsh show ltm pool SorryPool field-fmt | grep -o "status.status-reason The pool is available" > /dev/null
if [ $? != 0 ]; then
status=1;
fi
tmsh show ltm pool PajoIIS-8080-8081_pool field-fmt | grep -o "status.status-reason The pool is available" > /dev/null
if [ $? != 0 ]; then
status=1;
fi
if [ $status == 0 ];
then
rm -f $pidfile
echo "up"
fi
Note that this will also bring the pool down if the pools being checked are in an unknown state though. If you want to take that into account I'd recommend writing a function checking both monitor state and enabled state.
/Patrik