Created
December 20, 2019 20:46
-
-
Save fernandozamoraj/d4a41be673c0b2890572f51a1dfe7d10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 urllib.request | |
import ctypes | |
import time | |
from datetime import datetime | |
page_name = "my page" #change to what you want your message to display | |
page_url = "https://www.google.com" #change to your website... | |
start_time = datetime.now(); | |
failure_count = 0 | |
sleep_interval = 60 | |
while True: | |
code = 0 | |
try: | |
code = urllib.request.urlopen(page_url).getcode() | |
except: | |
code = 300 | |
print("request to " + page_name + " failed") | |
now = datetime.now() | |
current_time = now.strftime('%H:%M:%S') | |
if(code != 200): | |
failure_count += 1 | |
print(page_name + " is down...failure count: " + str(failure_count) + " at " + current_time) | |
if(failure_count % 10 == 0): | |
ctypes.windll.user32.MessageBoxW(0, page_name + " is down as of " + current_time , page_name + " is down", 1) | |
else: | |
if(failure_count > 0): | |
failure_count = 0 | |
start_time = datetime.now() | |
print(page_name + " is backup and AOK at " + current_time) | |
else: | |
print(page_name + " is AOK at " + current_time) | |
alive_time = now- start_time | |
print("Alive for " + str(alive_time)); | |
time.sleep(sleep_interval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment