Last active
August 29, 2015 14:18
-
-
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.
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
### 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