#!/usr/bin/python# this script can be used to monitor url's for uptime. # (C)opyright Nimret Sandhu -http://www.nimsoft.bizimport urllib2 import smtplib import datetime from email import * from email.Utils import *# list of url's which needs to be monitored urls = ('http://your.domain.org/some/url', 'http://another.domain.com')# email settings mailServer = 'your.mailserver.com' fromAddr = 'your app < your@app.com>' # from field toAddr = 'your@email.com' # to field subject = 'Error loading Url(s)' badUrls = [] # stores the bad urls for reportingdef ok( url): 'checks to see if an url gives a 404 or not' try: f = urllib2.urlopen( url) return 1 except: return 0def error( badUrls): 'sends out an error email with bad list of urls' msg = Message.Message() msg['From'] = fromAddr msg['To'] = toAddr msg['Date'] = formatdate(localtime=True) msg['Subject'] = subject text = 'Could not load:rn' for badUrl in badUrls: text = text + ' ' + badUrl + 'rn' msg.set_payload( text) s = smtplib.SMTP( mailServer) s.sendmail( fromAddr, toAddr, msg.as_string()) s.quit()# MAIN SCRIPT START for url in urls: if not ok( url): badUrls.append( url) # send an email if there were any bad urls if len( badUrls) > 0: error( badUrls)
| snipsnap-index | My Python Scripts | Daily Stuff |
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |



Powered by SnipSnap 1.0b2-uttoxeter