One of my recent Citrix KB articles was about creating a Netscaler user monitor (which are Perl based) to allow for a more intelligent type of monitoring for AJP based services than a standard TCP based socket open/close check. The AJP Protocol Reference is good enough to provide a method for doing a simple and lightweight PING/PONG request/response. Unfortunately, the format of the packets is such that they cannot (currently) be added as a TCP-ECV monitor, essentially because of restrictions on non-printable characters being inserted into those monitors (believe me, I tried multiple ways to insert the required characters).
So, I set off to write the Perl version of such a monitor, but before I did I needed a simple script outside the Netscaler for debugging purposes – having to rely on the monitor for testing is needlessly cumbersome, better to get it functioning first and then add it to the monitor code later. Also, because of that approach, the script is perfectly usable as a generic test and is written almost entirely as a self-contained sub-routine (anyone that has seen the user monitor structure on the Netscaler will instantly recognize that also). Hence, I think it would be very easy to add the subroutine to a syslog or other monitoring type script. Therefore I decided to share the more generic version here. The full code is after the jump, if you prefer a more compressed binary version you can find it here: ajp.pl.gz
I have the acknowledgements in the code also, but to get them in before the jump, they were invaluable:
- The hex values are based on the information from http://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html#Packet%20Headers
- Actual pack code to create the hex packets is from http://it-nonwhizzos.blogspot.com/2009/05/ajp-ping-in-perl.html