Forum Discussion
iRule to disable VIP with less then X members a pool
That's an interesting use case, and it's a little sad that this isn't just an option in the config. There's probably a few ways to do this, but here's what I've come up with using an external monitor. Add this monitor script to a pool that already has a good working monitor and make sure the Availability Requirement setting is set to All.
!/bin/sh
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
pool=local-pool
minup=2
virtual=access-test-vs
upmembers=`tmsh show /ltm pool $pool members |grep "Current Active Members" |awk -F" : " '{ print $2 }'`
if [ $upmembers -ge $minup ]
then
rm -f $pidfile
state=`tmsh show /ltm virtual $virtual |grep "State" |awk -F" : " '{ print $2 }'`
if [ $state == "disabled" ]
then
logger -p local0.info -t MONITOR-ALERT "Pool $pool Monitor UP - enabling virtual $virtual"
tmsh modify /ltm virtual $virtual enabled
fi
echo "up"
else
rm -f $pidfile
state=`tmsh show /ltm virtual $virtual |grep "State" |awk -F" : " '{ print $2 }'`
if [ $state == "enabled" ]
then
logger -p local0.info -t MONITOR-ALERT "Pool $pool Monitor DOWN - disabling virtual $virtual"
tmsh modify /ltm virtual $virtual disabled
fi
echo "up"
fi
The script itself always reports "up" to the monitor because its job is simply to monitor the number of available members, compare that to the "minup" value, and then enable or disable the VIP (if it's already disabled/enabled respectively). Also notice that I hard-coded the pool, minup and virtual values:
pool=local-pool
minup=2
virtual=access-test-vs
You could very easily turn those into arguments in the external monitor config:
ltm monitor external test_nodesup_monitor {
args "local-pool 2 access-test-vs"
}
That way the script could use $3 (the pool), $4 (minup), and $5 (virtual server) instead of the hard-coded values. You'll still need to create a separate external monitor config for each VIP (and pool) that you want to work with.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com