Skip to content

Instantly share code, notes, and snippets.

@th3o6a1d
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save th3o6a1d/6035e80f239d234b5ecf to your computer and use it in GitHub Desktop.
Save th3o6a1d/6035e80f239d234b5ecf to your computer and use it in GitHub Desktop.
The Poor Man's Server Monitor -- Uses email-to-text to notify if server status code != 200.
### If using gmail, you will need to log in and confirm 'insecure app' settings
import requests
import smtplib
import time
while True:
try:
r = requests.get('http://sitetocheck.com')
if r.status_code != 200:
raise Exception('Status code: ' + str(r.status_code))
except:
sender = 'Sender'
receiver = 'xxxxxxx@messaging.sprintpcs.com'
message = "Server Down"
smtp_server = 'smtp.gmail.com'
email = 'xxxxxxx@gmail.com'
password = 'xxxxxxxxxx'
smtpObj = smtplib.SMTP(smtp_server, 25)
smtpObj.starttls()
smtpObj.login(email, password)
smtpObj.sendmail(sender, receiver, message)
smtpObj.quit()
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment