Skip to content

Instantly share code, notes, and snippets.

@iign
Created October 2, 2013 20:52
Show Gist options
  • Save iign/6800372 to your computer and use it in GitHub Desktop.
Save iign/6800372 to your computer and use it in GitHub Desktop.
Simple site monitor. Gets urls from text file and checks http status code for each.
#!/usr/bin/env
import httplib
file_list = open('sites.txt', 'r')
def check_site(url):
conn = httplib.HTTPConnection(url)
try:
conn.request("HEAD", "/")
except Exception, e:
return None
else:
response = conn.getresponse()
return response
lines = file_list.readlines()
print lines
for site_url in lines:
print site_url
site = check_site(site_url.strip())
print site_url + ' status: ', site.status, site.reason
if site.status > 400:
print 'ERROR. Notify.'
file_list.close()
google.com
example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment