Roll Your Own Site Checker with Python


2013-10-20

There are tons of services out there that will monitor the status of a website for you. Pingdom, Uptime Robot, etc all will watch a site and inform you if it is down. Since it's trivial to check a site's status, I wrote my own equivalent using Python. Here it is:

Site Checker with Python

This checks a website (argument #1) and will send me an email if the site is down twice in 30 seconds. All you need is the Requests module for Python and an smtp server:

sudo apt-get install python-setuptools
sudo easy_install requests

I use a throwaway gmail account for my smtp server, so the password being in plaintext in the script isn't a big issue. Just replace the email addresses with your own on lines 31, 32, and 34.

I added this line to my crontab, running the site-checking script every 15 minutes:

*/15 * * * * python ~/path/to/script/checksites.py http://mysite.com

This will check http://mysite.com every 15 minutes and email me if it sees a non-200 http return status or an exception.