Forum Discussion
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"><abc>XXX<abc><MsgID>0001<MsgID>. When the success is received, the application is considered normal. When MsgID is a fixed value, it has been tested successfully. Now we want to add 1 to MsgID every time, from 0001 to 9999. Excuse me, how can this be achieved?
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.
- cjunior
Nacreous
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.
- jian
Altocumulus
Thanks,i will try😄
- jian
Altocumulus
if the member is ok,it will replay “000000”,How add this to my external monitor
- cjunior
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.
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