I hope someone will find this useful:
### # Hamid Alipour ### ### # Config ##################################################### urls = ['http://www.P U T Y O U R U R L S H E R E.com/'] url_timeout = 5 sleep_time = 5 * 60 failed_count_before_alarm = 10 sleep_time_on_failure = 15 ##################################################### import urllib2 import winsound import time class SiteMonitor: def __init__(self): pass def start(self): while True: for url in urls: if not self.check_url(url): if not self.is_it_live(url): self.alarm() self.sleep(sleep_time) def is_it_live(self, url): failed_count = 0 while failed_count < failed_count_before_alarm: if not self.check_url(url): failed_count += 1 else: return True self.sleep(sleep_time_on_failure) return False def check_url(self, url): print 'Checking...' + url + '...', try: urllib2.urlopen(url, timeout=url_timeout) except: print 'Failed!' return False print 'Done it\'s up!' return True def alarm(self): print 'Too many failures...' while True: print 'Alarm...' winsound.PlaySound("SystemExit", winsound.SND_ALIAS) def sleep(self, seconds): print 'Sleeping for ' + str(seconds) + ' second(s)...' time.sleep(seconds) print 'Waking up...' def main(): SiteMonitor().start() if __name__ == "__main__": main()
Save it as sitemonitor.py and run it like:
python sitemonitor.py
Or just double click on the file.
Please note: in order to run this, you will have to install Python:
http://www.python.org/download/
Hamid Alipour is a partner in Codehead, LLP with his wife, Tess. Hamid speaks 12 markup and programming languages [Yes, 12: PHP, CSS, Ajax, JavaScript, HTML/XHTML, Java, Python, C/C++, ASP, Visual Basic, Scheme and Action Script]; has a penchant for solving the unsolvable; an affinity for clean, hand-written code and is a Zend Certified 
the beast!!
Comment — August 12, 2009 @ 2:37 am