Custom TCP Monitor

I am looking to do some custom TCP monitoring with a custom application that we need to monitor with the F5. Essentially, the application’s thread handling logic will hang unless a specific set of send and receive steps are performed:

1. TCP handshake is established

2. Client sends a custom string.

3. Server sends a char in acknowledgement.

4. Client sends message header.

5. Client sends message body.

6. Server sends response header.

7. Server sends response body.

8. TCP close occurs.

The custom TCP monitors I can make on the F5 don’t allow me to follow this kind of send and recieve logic. Is there a way to perform these steps with some kind of custom monitor?

Here is a link to something that can be done via custom shell script.

http://devcentral.f5.com/wiki/default.aspx/AdvDesignConfig/HTTPMonitor\_cURL\_BasicPOST.html

In this example they are using cURL to send information and expect a return. You could end up writing some IF ELSE statement which would ultimately result in a status that is either UP or DOWN

I hope this helps

CB

An external monitor might work well. But, to make the call directly, we would need to build our own executable and place it on the F5. There are some maintanence issues with doing this, so we would rather not go that route if we can help it. Any other methods we can use here?

I think I found an excellent way to create this monitor. I found that if we call these apps by passing all of the pieces at once, the application works fine. After digging a bit, I was able to find ways to embed all of the special characters that are needed for a request to the application into the Send field in a custom TCP monitor:

However, I ran into a wall that I don’t know if I can scale. The send string includes ASCII null chars. These should be able to be escaped as:

\x00

However, it seems the BIG-IP web interface doesn’t allow these chars. For, I got an error when trying to add the custom monitor (see attachment). Is there some other way to get these into the system?

Per SOL4186 I don’t think you’ll be able to use a null in the send or receive string:

“Note: The BIG-IP system does not allow the ASCII character 0 (NUL).”

I tried adding this in both \x00 and \x000 format through the GUI, the CLI and the bigip.conf file but all attempts resulted in the ‘embedded zero’ error.

You could either check with F5 Support on why this restriction is in place or use an external monitor to send the null. A standard TCP monitor would be simpler and more efficient, so it might be worth checking with F5 on this.

Aaron

I have contacted Tech Support. We will see what they have to say. I’ll post their response here when I get it. Thanks for all your help so far.

Tech Support said that there have been a few other requests for this kind of thing. However, they didn’t know the reason for the design. They will be investigating further. They thought the NUL char was used as a delimiter for the monitor program. Hopefully, the developers can find the time and methods to fix this. We would certainly appreciate it.

For now, I will use an external monitor in conjunction with netcat and see if I can simulate the same functionality. Thanks for your help.

Using netcat from an external monitor is a good workaround. I’d be interested in what Support finally comes back with. Please do reply back when you get feedback from them.

Thanks,

Aaron

I’ll post what they tell me. I’ll also share what I eventually come up with using netcat. Hopefully, it works just as well as the native TCP monitor.

From what I’ve read from Deb in particular, an external monitor will never be as efficient as using an inbuilt monitor. So having F5 provide support for nulls in the send string would probably be the most efficient solution. But please do post your netcat based solution.

Thanks,

Aaron

Alright, I have implemented an external monitor script and the monitor profile needed to run the script from within the F5. Running the script from the prompt works fine. The following call returns “UP” when the application is listening properly and nothing when it is not.

bash runBerryCall 10.1.1.1 18888

However, the same pool member is marked down by the monitor when the BIG-IP runs the external monitor. See attachment for the monitor’s settings.

I’m guessing the reason for this is the IP address format that is passed to the script. From the articles I have found, it seems the IP is passed in “IPv4 mapped address notation”:

http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=151

For, netcat doesn’t like the format of the IP address. This fails with the following error:

bash runBerryCall ::ffff:10.1.1.1 18888  
 ::ffff:10.1.1.1: forward host lookup failed: Unknown host

NetCat 6 fully supports IPv6. How can I figure out what version of netcat is installed on the BIG-IP?

The version from a 9.4.7 unit is 1.10:

nc -h

[v1.10]

You can remove the IPv6 prefix in your script using ‘sed’, as in the sample from the article you linked:

remove IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)

IP=`echo ${1} | sed ‘s/::ffff://’`

Aaron

Excellent. Thank you. That solved my IP issues. But, the pool member is still marked as down even though running the script from the prompt returns “UP”. What might be going on?

I have included the contents of my script and the bytes sent to the application. Also attached is the screenshot of the current operation of the script.

(I have added a “.txt” to the runBerryCall file so it can be uploaded. But otherwise it is the same file as what is on the BIG-IP.)

Here is a couple more screenshots that might help.

One more thing: I just tried a basic version of this script that just echos “UP” to the console:

echo "UP"

As expected, running it from the command line always prints “UP”. However, attaching an external monitor that uses the script to a pool still shows all of them as down. I would expect that this would show all members as up. So, something must be problematic with my set up. Any ideas?

You might try adding !/bin/bash to the top of your script"

!/bin/bash 
 ip=`echo ${1} | sed 's/::ffff://'`  
 output=$(nc $ip $2 < berryCall.txt -w 5) 
 echo $output 
 if [[ $output == *BusinessCode* ]] 
 then echo "UP" 
 fi

Once you get that working, you could bring the berryCall.txt code into the script so you’re not having to access a second file.

Aaron

That fixed it! Thank you. I will post the full script as soon as I have put the extra chars in the main script.

I am a bit of a newbie to BASH. So, I am running into trouble encoding the input properly into my script. Mind if you help me set it up correctly? Here is what I have so far:

!/bin/bash  
 ip=`echo ${1} | sed 's/::ffff://'`  
 port=${2}  
 input="FDCB^_^@^@^@Service=RC_SERVICE^^Command=Ping^@^@^@^@"  
 output=$(echo $input | nc $ip $port -w 5)  
 if [[ $output == *BusinessCode* ]]  
 then echo "UP"  
 fi

When executed, the script waits 1-2 seconds and then pushes nothing to output. After echoing back the input and output variables, it seems the input variable is not being encoded properly. How do I properly encode the extended ASCII chars into a BASH variable?

The problem is the echo command, right? I noticed that extended ASCII don’t get repeated back at the prompt when I type in something similar to this:

echo -e "--- \0000 ---" 
 ---  ---

What other command will allow me to pipe in the proper input to netcat?

The echo command should be working okay. You won’t see a null character echoed to standard out, as it’s not a printable character. But xxd shows the null character as 00 in hex. od shows it as the escape sequence \0. You’ll also probably want to suppress the trailing newline character echo adds by default by adding \c to the end of the echo string. See below for some examples.

If you view the monitor script with a hex editor like xxd or od, are the ^@ chars actually 00 (null in hex)? Or are they literally ^ and @? Can you upload the file?

You might try converting the entire send string into either octal \000 or hex \x00 to avoid any encoding issues.

Example using hex format of \x00

echo -e “0123\x00456”| xxd

0000000: 3031 3233 0034 3536 0a 0123.456.

Example using octal format of \0000

$ echo -e “0123\0000456”| xxd

0000000: 3031 3233 0034 3536 0a 0123.456.

od (utility to dump files in octal and other formats) shows the escape sequences for the unprintable character(s):

Example using hex format of \x00

$ echo -e “0123\x00456”| od -t c

0000000 0 1 2 3 \0 4 5 6 \n

0000011

Example using octal format of \0000

$ echo -e “0123\0000456”| od -t c

0000000 0 1 2 3 \0 4 5 6 \n

0000011

You can prevent echo -e from appending a newline character to the end of the string using \c:

$ echo -e “0123\x00456\c”| od -t c

0000000 0 1 2 3 \0 4 5 6

0000010

Aaron