Updated version of content-check

After finishing the first version of content-check, I thought about a few additional features I wanted to add. One feature was the ability to include arbitrary HTTP headers in requests, and a second feature was the ability to selectively generate email, syslog entries or logfiles entries per site. After pondering the best way to add these capabilities, I decided to rewrite content-check in Perl. The new version works similarly to the old version, but the structure of the configuration file is different.

The configuration file now contains one or more configuration stanzas, and each configuration stanza contains a site definition. Each site definitions starts with a description enclosed in brackets, followed by one or more key-value pairs. Here is the site definition file I use to monitor prefetch.net:

$ cat sites.cfg

# Monitor static content
[site pair_static]
url = http://prefetch.net/index.html
checksum = 955abe0f861480103b59f464d6037b3febd6c89c
header = "Host: prefetch.net"
logfile = /var/log/content-check/pair
syslog = yes
email = sysadmin@prefetch.net

# Monitor the PHP engine / MySQL Database
[site pair_dynamic]
url = http://prefetch.net/test.php
checksum = 0e61ac076628741cfc4d4828b1cc905e5e6e86b9
header = "Host: prefetch.net"
logfile = /var/log/content-check/pair
syslog = yes
email = sysadmin@prefetch.net

To generate the checksum for a specific URL, you can run content-check.pl with the “-g” option:

$ content-check.pl -g http://prefetch.net/index.html

Checksum for http://prefetch.net/index.html is:

Once the configuration file is created, content-check.pl can be run with the “-c” option, and the name of the configuraiton file:

$ content-check.pl -c sites.cfg

If the script locates a site that fails to checksum to the stored checksum, it will send an email, generate a syslog entry, or create a generic logfile entry similar to the following:

Content-check detected a problem with http://prefetch.net/index.html:
Site definition: prefetch_static
Date: Sun Dec 17 21:40:03T2006:00-04:00
URL: http://prefetch.net/index.html
Precomputed checksum: 955abe0f861480103b59f464d6037b3febd6c89c
Current checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709

I find this script useful for monitoring the web infrastructure I support, and the new version was fun to write (this was the first time I mucked with Perl references). Shibby!

This article was posted by Matty on 2007-01-05 13:44:00 -0400 -0400