Sunday, October 2, 2011

A Perl URL checker

URL::Check : yet another URL check system
You want to get notified is something goes weird on a web site you develop and that should be running 24/7?
Given a list of url, you want to check if they exist and send receive an email in case of trouble.
The problem is so common and hundreds of solutions exists on the web, from simple crontab shell to more complex system (hyperic & co).
We propose here one more system. The constraints were:

  • check availability of url, response time or contents,
  • get email to be notified in case of failure,
  • a simple configuration system.
Installation
Perl is perfect for that task. Install URL::Check from CPAN
 sudo perl -MCPAN -e 'install URL::Check'
A script url-check.pl is installed in the default script directory.
To get mail sent, your server must be able to sendmail with basic sendmail...
Run it
url-check.pl --config=my-config.txt
Or add in crontab, to get it run every hour:
0 * * * * url-check.pl --config=my-config.txt
Configuration
Well, everything resides here. Here is an example from the CPAN package
#report errors on console
onerror.console=true
#report errors via mail
onerror.mailto=alexandre.masselot@gmail.com
#just check if the page can be loaded
http://www.facebook.com
#check is this page can be loaded in less than 30s
http://www.apple.com
check.overtime=30000
#we check for the google page in 5ms, so that should produce an error...
http://www.google.com
check.overtime=5
#check that a text is contained in a url. Those should produce error
http://www.apple.ch
check.contains=microsoft is the best
check.contains=ipad is only for dummies
#this should work
http://www.google.ch
check.contains=o

2 comments:

  1. Hi Alexandre,
    Any chance this module can check SSL and other ports (not 80)

    Thanks

    ReplyDelete
  2. I tried on a port 8083 without any trouble (should be the same on https (it is using LWP::Simple to get the url, nothing fancy).
    Alex

    ReplyDelete