Skip to content

Instantly share code, notes, and snippets.

@exiva
Created March 19, 2015 02:29
Show Gist options
  • Save exiva/d767ee1b3c9a4cd8ea68 to your computer and use it in GitHub Desktop.
Save exiva/d767ee1b3c9a4cd8ea68 to your computer and use it in GitHub Desktop.
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