Created
March 19, 2015 02:29
-
-
Save exiva/d767ee1b3c9a4cd8ea68 to your computer and use it in GitHub Desktop.
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 datetime | |
import requests | |
import subprocess | |
import time | |
def tryHTTP(): | |
url = 'https://google.com' | |
now = datetime.datetime.now() | |
try: | |
r = requests.get(url) | |
except requests.exceptions.ConnectionError as e: | |
print "[{}:{}] Exception: {}".format(now.hour, now.minute, | |
e) | |
runDiags() | |
else: | |
if r.status_code != 200: | |
print '[{}:{}] Got a error: HTTP Status code: {} Running diags:'.format( | |
now.hour, now.minute, r.status_code) | |
runDiags() | |
print "End diag report." | |
def runDiags(): | |
subprocess.call(["ping", "-c 2", "google.com"]) | |
subprocess.call(["traceroute", "google.com"]) | |
subprocess.call(["open", "https://google.com"]) | |
def loopz(): | |
while True: | |
tryHTTP() | |
time.sleep(60) | |
if __name__ == '__main__': | |
loopz() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment