Created
October 10, 2012 21:46
-
-
Save mivanov/3868665 to your computer and use it in GitHub Desktop.
Quick site monitoring script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle, os, sys, logging | |
from httplib import HTTPConnection, socket | |
from smtplib import SMTP | |
import pynotify | |
import time | |
pynotify.init("Monitoring") | |
def show_message(message): | |
n = pynotify.Notification("Status", message) | |
n.show() | |
def get_site_status(url): | |
response = get_response(url) | |
try: | |
if getattr(response, 'status') == 200: | |
return 'up' | |
except AttributeError: | |
pass | |
return 'down' | |
def get_response(url): | |
'''Return response object from URL''' | |
try: | |
conn = HTTPConnection(url) | |
conn.request('HEAD', '/') | |
return conn.getresponse() | |
except socket.error, e: | |
print e | |
return None | |
except Exception, e: | |
show_message("Exiting") | |
exit(1) | |
import sys | |
url = sys.argv[1] | |
show_message('Monitoring ' + url) | |
while True: | |
if get_site_status(url) != 'up': | |
show_message(url + ' is down') | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment