Forum Discussion
gof5go_289559
Apr 28, 2017Nimbostratus
I ended up creating an external file monitor with the following. Still need to fix the "-k" requirement on the curl command...
In the LTM health monitor, add a variable with the Name of HOST_NAME and the Value of the host's name as seen by Nagios.
This could easily be re-purposed to check any service's status in Nagios...
!/bin/sh
This script expects the following Name/Value in the LTM monitor and no Arguments are needed
HOST_NAME = the monitored host name in Nagios
remove IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)
IP=`echo ${1} | sed 's/::ffff://'`
PORT=${2}
PIDFILE="/var/run/`basename ${0}`.${IP}_${PORT}.pid"
kill of the last instance of this monitor if hung and log current pid
if [ -f $PIDFILE ]
then
echo "EAV exceeded runtime needed to kill ${IP}:${PORT}" | logger -p local0.error
kill -9 `cat $PIDFILE` > /dev/null 2>&1
fi
echo "$$" > $PIDFILE
send request & check for "current_state:0"
curl -kfNs "https://nagiosserver.local/nagiosxi/api/v1/objects/servicestatus?host_name=${HOST_NAME}&service_description=crond&apikey=[api-key-here]" | grep -i "\"current_state\":\"0\"" 2>&1 > /dev/null
mark node UP if true
if [ $? -eq 0 ]
then
rm -f $PIDFILE
echo "UP"
else
rm -f $PIDFILE
fi