Receive Alerts on the Go

How can you find out if your web server is down? You can set up your desktop to notify your Palm device when something happens.

You shouldn’t have to manually checkto see if your web site is up or not. Technology should be able to handle mundane chores like this. If you have a smartphone or wireless Palm device, then why not have it alert you when something goes wrong?

On your desktop machine, set up a simple script that checks to make sure your web site is alive. If the web site is down, then the script can send a text message (SMS) or an email [Hack #35] to your Palm device to let you know.

Test the following Python script out to make sure it works for you. Also, try running it with a non-existent URL to verify that the notification is working. Once the script is working, you can set up a cron job (Linux or Macintosh) or add it to Scheduled Tasks for Windows XP.

The Code

 """Check to see if a given web site is up or not. Usage: python check_site.py <URL> """ import os, sys, urllib2, smtplib # The following variables should be redefined to fit your system _smtp_server = "outgoing.example.com" # If you need to use SMTP AUTH, set this to 1. # You will also need to set an SMTP user name and SMTP password _authentication_required = 0 _user = "" _password = "" _to = "user@example.com" _from = "webserver@mydomain.com" _num_tries = 3 def is_site_up(url): """Checks to see if the given site is up""" try: urllib2.urlopen(url) return True except: return False def check_site(url): ...

Get Palm and Treo Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.