Created
March 7, 2016 09:16
-
-
Save ogrigas/337679e89124dec9338d to your computer and use it in GitHub Desktop.
Example Python script that pings a website and sends email alert in case it's unreachable
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
from urllib2 import urlopen | |
def send_alert(): | |
from smtplib import SMTP | |
from email.mime.text import MIMEText | |
msg = MIMEText('nuf said') | |
msg['Subject'] = 'inventi.lt is unreachable' | |
msg['From'] = 'osvaldas@inventi.lt' | |
msg['To'] = 'osvaldas@inventi.lt' | |
server = SMTP('smtp.gmail.com:587') | |
server.ehlo() | |
server.starttls() | |
server.login('username', 'password') | |
server.sendmail('osvaldas@inventi.lt', ['osvaldas@inventi.lt'], msg.as_string()) | |
server.quit() | |
try: | |
urlopen('http://inventi.lt/xxx') | |
print 'OK' | |
except: | |
send_alert() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment