#!/usr/bin/env python sites = [ 'google.com', ] USE_BOXCAR = True USE_GROWL = True BOXCAR_EMAIL = '' BOXCAR_API_KEY = '' BOXCAR_API_SECRET = '' import sys, os, urllib, urllib2, hashlib, datetime now = datetime.datetime.now() errors = [] def send_notice(site, code): if USE_BOXCAR: api_url = 'http://boxcar.io/devices/providers/%s/notifications' % BOXCAR_API_KEY data = { 'email': hashlib.md5(BOXCAR_EMAIL).hexdigest(), 'secret': BOXCAR_API_SECRET, 'notification[from_screen_name]': site, 'notification[message]': code, 'notification[from_remote_service_id]': u'%s-%s' % (now.strftime('%c'), site) } urllib2.urlopen(api_url, urllib.urlencode(data)) if USE_GROWL: os.system('growlnotify -n "Website Monitor" -p 2 "%s" -m "%s" -s' % (site, code)) for site in sites: try: urllib2.urlopen('http://%s' % site, None, 30) except urllib2.HTTPError, code: send_notice(site, code) errors.append(site) except urllib2.URLError, error: error = str(error) if error.find('Errno 8') > -1: send_notice(site, u'Does not appear to exist.') else: send_notice(site, u'%s' % error) errors.append(site) except: errors.append(site) if len(errors): print u'%s encountered errors.' % ','.join(errors) else: print u'All sites checked out.' sys.exit()