Keeping an eye on your HIP

As promised to the HORIZON-L mailing list, here’s a Perl script we use to monitor our HIP server:

www.daveyp.com/blog/stuff/monitor/monitor.pl

Once you’ve downloaded it, rename the file to monitor.pl

In summary, the script checks two URLs and sends an email to one (or more) email addresses if a trigger is reached:

(1) the first check is that your HIP home page is returning a 2xx HTTP status code

(2) the second check is that a HIP keyword search is returning results

Here are the gory technical details for getting this script up and running…

Requirements

Perl and the Mail::Sender module (any decent Perl hacker will be able to tweak the code to use a different method of sending the email).

Our script runs on a Windows PC, but you should be able to get it running on any machine that can run Perl.  The machine will need to be able to send emails, so you might need to check with your IT Dept to find out what the SMTP server IP address and whether or not you are allowed to send emails through it.

If you’re running Windows, then go for the free version of ActivePerl and then use PPM to download and install the Mail::Sender module — for most people, that just means running the following command from a DOS box:

ppm install Mail-Sender

How to Run the Script

You’ll want to periodically run the script to check on your HIP server.  How often you run it is totally up to you, and that will affect how quickly you’ll receive an email alert.  To run the script automatically, set up a scheduled task (Windows) or a cron job (Linux/Unix/etc).

Script Configuration

There’s a whole pile of variables you can tweak…

$sendEmailTriggerHome

This controls the trigger for sending an email if your HIP home page isn’t responding with a “2xx” code and should be set to a number.

If you set it to 0 (zero), then it disables the trigger and you’ll never get an email.

If you set it to 1, then you’ll get an email when the script runs and your HIP isn’t online — this might happen when you’re restarting your HIP (i.e. a false alarm!).

If you set it to a number greater than 1, then the trigger is reached when that number of subsequent checks have failed — if you run the script every 5 minutes and the trigger is set to 4, then you’d expect to receive an email after your HIP has been down for 20 minutes.

If your HIP returns a “2xx” status (i.e. it’s online), then the script resets its own internal counter.

If you don’t mind receiving an alert when you’re restarting HIP, then I’d recommend setting it to 1, other set it to 2.

$sendEmailTriggerSearch

This controls the trigger for sending an email if your HIP isn’t returning results for a keyword search and should be set to a number.

If you set it to 0 (zero), then it disables the trigger and you’ll never get an email.

If you set it to 1, then you’ll get an email the first time the script runs and your HIP isn’t returning results — this might happen when you’re running your reindexer (i.e. a false alarm!).

If you set it to a number greater than 1, then the trigger is reached when that number of subsequent searches have failed to produce results — if you run the script every 5 minutes and the trigger is set to 4, then you’d expect to receive an email after your HIP has been returning zero results for 20 minutes.

If you don’t mind receiving an alert when you’re running the reindexer, then I’d recommend setting it to 1.

@emailList

This is a list of email addresses, separated by whitespace.  Whenever a trigger is reached, an alert will be sent to each of the email addresses in the list.

$hipServerHome

Set this to the actual home page of your HIP server — for most people (everyone?) this will include a profile name e.g.
http://webcat.hud.ac.uk/ipac20/ipac.jsp?profile=cls#focus

$hipServerSearch

Set this to the URL of a suitable keyword search.  The easiest way to do this is to run a keyword search and then copy the URL from the web browser.

If you’d prefer to be gentle on your HIP, then you can also use a “GetXML=true” style URL — the XML response is much smaller than the HTML one.

$hipSearchType

Depending on what type of search URL you used (HTML or XML), set this variable accordingly.

The script works by running a regular expression against the HTML (or XML) returned from the supplied URL to find out how many results were found.

$logTemp

The script needs a temporary log file so it can remember what happened the last time it ran.  The script needs to be able to write to the file, so you may need to set up appropriate file/folder permissions.

$smtpServer

Set to the IP address of the SMTP mail server you want to send the email to.

$fromAddress

Set to the “from” address you want the email alerts to appear to be sent from.

$httpProxy

If you need to go through a HTTP proxy server to access your HIP server, then set this to a suitable value (e.g. http://proxy.my.edu:3128), otherwise set it to an empty string ("").

Footnotes

As with most of these things, the script comes with no guarantees.  If you’re having problems, see if you’ve got a local Perl guru in the IT Dept — chances are he’ll have a beard and be wearing sandals!

The script works fine on our HIP 3.08 install, but mileage may vary with other versions.