For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

jian's avatar
jian
Icon for Altocumulus rankAltocumulus
Jul 23, 2019
Solved

how to create a tcp xml external health check.

Hello everyone, I want to create a new external health check. This is an application for sending XML messages by TCP. It is similar to the client sending 011101<?xml version="1.0" encoding="UTF-8"><a...
  • cjunior's avatar
    Jul 31, 2019

    Hi,

    Have you tried to use istats to store the counter?

    This is the only way I can see now.

    e.g.

    #!/bin/sh
     
    #
    # these arguments supplied automatically for all external pingers:
    # $1 = IP (::ffff:nnn.nnn.nnn.nnn notation or hostname)
    # $2 = port (decimal, host byte order)
    # $3 and higher = additional arguments
    #
    # $MONITOR_NAME = name of the monitor
    #
    # In this sample script, $3 is the regular expression
    #
     
    # 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
     
    # Remove the IPv6/IPv4 compatibility prefix
    node_ip=`echo $1 | sed 's/::ffff://'`
    port=$2
     
    # Define istats key to store values
    # Each node has a unique counter
    istats_key="ltm.monitor ${node_ip}_${port} counter msgID"
     
    # Increase value on node counter
    istats incr "$istats_key" 1
    # Get the current counter value
    value=`istats get "$istats_key"`
     
    # Keeping value between 1 and 9999 (4 digits)
    if [[ $value -eq 0 || $value -gt 9999 ]]; then
        value=1
        istats set "$istats_key" $value
    fi
     
    # Using the nc utility to get data from the server. 
    # Search the data received for the expected expression
    echo '011101<?xml version="1.0" encoding="UTF-8"><abc>XXX</abc><MsgID>'$(printf "%04d" $value)'</MsgID>' | /usr/bin/nc $node_ip $port 2> /dev/null | grep -E -i $3 > /dev/null
     
    status=$?
    if [ $status -eq 0 ]
    then
        # Remove the pidfile before the script echoes anything to stdout and is killed by bigd
        rm -f $pidfile
        echo "up"
    fi
     
    # Remove the pidfile before the script ends
    rm -f $pidfile

    I hope it helps.