Forum Discussion
how to create a tcp xml external health check.
- 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 $pidfileI hope it helps.
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 $pidfileI hope it helps.
if the member is ok,it will replay “000000”,How add this to my external monitor
- cjuniorAug 02, 2019
Nacreous
Well,
In this monitor example, you should use the arguments to pass the value.
e.g.
I suggest you to adapt the script the way you feel comfortable.
The goal here is a way to store a count variable.
Regards.
- jianSep 03, 2019
Altocumulus
Sorry, I just saw it today, you may misunderstand what I mean. F5 does not need to send the parameters of 000000 to the server. When f5 sends the probe, if the server receives the impact message of 000000 , that is, the server replies 000000 to F5, the server is considered normal.
- cjuniorSep 03, 2019
Nacreous
Hi, it's OK and I think I got it at first time.
The third and additional argument on script is related to the expected response.
So, the first and second are implicit args because BIG-IP will pass that IP address and port number.
Then, the third and last parameter should be the expected on the replies.
Note:
# $1 = IP (::ffff:nnn.nnn.nnn.nnn notation or hostname)
# $2 = port (decimal, host byte order)
# $3 and higher = additional arguments
# 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
Regards.
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
