Custom DNS Service health monitoring for GTM and LTM

Problem this snippet solves:

This EAV monitoring is created for the purpose of custom GTM/LTM DNS health monitor. You will either use the custom health monitor to monitor your LTM pool members or GTM servers/pool members, or if you have preferred DNS servers to monitor, specify DNS servers within the monitor settings.

This custom monitoring is specifically created for v11.6.1. It may or may not work for other versions. Feel free to test it out.

How to use this snippet:

As described in the coding comments, save this code into a text file and import it into your GTM/LTM.

Create an external type monitor and enter the values written in the coding.

Assign the monitor to the pool or server like what you normally do to assign a typical monitor.

Do note that you can monitor EITHER the pool member / server OR specify your own DNS servers to monitor. Not both. Max allowed DNS server to monitor is 2.

If you would like to deploy this monitor on GTM, I suggest that you go thru K8154 first.

Code :

#!/bin/sh
    #
    # Author: Darren Neo
    # This EAV script is created for the purpose of custom GTM/LTM DNS health monitor.
    # In this script, you will either use the custom health monitor to monitor your LTM pool members or GTM servers/pool members,
    #   or if you have preferred DNS servers to monitor, specify DNS servers within the monitor settings. 
    # This script is specifically created for v11.6.1. It may or may not work for other versions. Feel free to test it out.
    #
    # To use this, import this script to the GTM/LTM: System  ››  File Management : External Monitor Program File List
    # Create custom external monitor on the GTM/LTM. 
    # Monitor settings: 
    #   Type: External
    #   External Program: select this imported script
    #   Interval: 10 seconds (LTM), 30 seconds (GTM)
    #   Timeout: 31 seconds (LTM), 120 seconds (GTM)
    #   Arguments: any name to be looked up. e.g. www.f5.com
    #   Variables (optional): DNS1, DNS2 - (specify DNS servers instead of using IP address from $1) 
    # For GTM, create the following: data centers, prober pool, server, pool witth pool member.
    #   - add the newly created custom external monitor to the previously created server, pool or pool member.
    # For LTM, create the following: pool with pool member
    #   - add the newly created custom external monitor to pool or pool member.
    #
    # $1 and $2 arguments will be supplied automatically for all external monitors, $3 will be the argument from the monitor that calls this script:
    # $1 = IP (nnn.nnn.nnn.nnn notation or hostname)
    # $2 = port (decimal, host byte order) -- not used in this monitor, assumes default port 53
    # $3 = name to be looked up
    # $DNS1 = variable from the monitor settings
    # $DNS2 = variable from the monitor settings
 
    node_ip=`echo $1 | sed 's/::ffff://'`
 
    pidfile="/var/run/`basename $0`.$node_ip..$2.pid"
    if [ -f $pidfile ]
    then
       kill -9 `cat $pidfile` > /dev/null 2>&1
    fi

    # echo "EAV `basename $0`: IP - $1, DNS1 - $DNS1, DNS2 - $DNS2, Lookup - $3" | logger -p local0.debug

    echo "$$" > $pidfile

    # if DNS1 and DNS2 servers are not supplied, we will use the $1 IP address that was automatically supplied from the system
    # if DNS1 and DNS2 servers are supplied, we will use DNS1 and DNS2 instead of $1

    if [ not $DNS1 ] && [ not $DNS2 ] 
    then
       ip=`dig +time=2 +tries=2 +short @$node_ip $3 IN A`
    fi

    if [ $DNS1 ]
    then
       dns1_result=`dig +time=2 +tries=2 +short @$DNS1 $3 IN A`
    fi

    if [ $DNS2 ]
    then
       dns2_result=`dig +time=2 +tries=2 +short @$DNS2 $3 IN A`
    fi

    # echo "Using system IP address: A-Record received: $ip" | logger -p local0.debug
    # echo "Using system DNS1 address: A-Record received: $dns1_result" | logger -p local0.debug
    # echo "Using system DNS2 address: A-Record received: $dns2_result" | logger -p local0.debug

    # verify if A-record is valid IP address.
    if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ $dns1_result =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ $dns2_result =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
    then
        # echo "UP" | logger -p local0.debug
        # Complete any cleanup activity before sending result to STDOUT as the script is stopped then.
        rm -f $pidfile
        echo "UP"
    else
        # echo "DOWN" | logger -p local0.debug
        rm -f $pidfile
    fi

Tested this on version:

11.6
Published Oct 13, 2017
Version 1.0

Was this article helpful?

No CommentsBe the first to comment