Netscaler


Using Perl to Ping an AJP Service (Jetty)

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 discrete or forkable version, you can find it on github here: ajp.pl

I have the acknowledgements in the code also, but to get them in before the jump, they were invaluable:


Netscaler NITRO API 101: Logging in with Python

UPDATE: 28/09/2011 – I have resolved the issues I was having with the Citrix blogging system and published an updated version of this post there:

Netscaler NITRO API 101: Logging in with Python

I’ll hopefully be an actual Citrix blogger soon, but in order to try this out, I thought I would post here first and see how it goes…..

If you are using one of the SDKs (Java or C#) then creating a NITRO session on the Netscaler is as simple as creating a new “nitro_service” object, choosing your connection method and setting your credentials appropriately. If have supplied valid credentials and your Netscaler is correctly configured then you can continue on your merry way and remain ignorant of what has just happened in the background. However, if you are looking to use another language to make use of the RESTful interface that NITRO provides, then you will need to know more.

The NITRO API Documentation is available from the Netscaler GUI, of course, but that serves as more of a functional specification than a guide to building a successful REST client in your language of choice. So, what exactly is required to take that first step and log in to a Netscaler?

The short answer is: A properly formatted POST request using appropriate credentials – easy, right?

Creating that properly formatted request, from scratch, can be more tricky that it appears. The exact requirements, along with an example, are after the break.