Forum Discussion
Jeremy_Bridges_
Nimbostratus
Aug 21, 2009Custom 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?
26 Replies
- hoolio
Cirrostratus
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 - Jeremy_Bridges_
Nimbostratus
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.) - Jeremy_Bridges_
Nimbostratus
Here is a couple more screenshots that might help. - Jeremy_Bridges_
Nimbostratus
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? - hoolio
Cirrostratus
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 - Jeremy_Bridges_
Nimbostratus
That fixed it! Thank you. I will post the full script as soon as I have put the extra chars in the main script. - Jeremy_Bridges_
Nimbostratus
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? - Jeremy_Bridges_
Nimbostratus
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? - hoolio
Cirrostratus
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 - Jeremy_Bridges_
Nimbostratus
Thanks for the tip about echo adding a newline character. I didn't know that. After I added the "\c" to the input it worked fine. In experimenting with it I ended up doing what you described: putting the escaped chars in a string and then coverting them to their actual chars using echo:input="FDCB\x1F\x00\x00\x00Service=RC_SERVICE\x1ECommand=Ping\x00\x00\x00\x00\c" output=$(echo -e $input | nc $ip $port -w 5)
Again, thanks for your help! I have attached the full script for anyone's future use. Let me know if you think there should be any further optimizations or changes.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
