diff --git a/monitor.py b/monitor.py index 3fe90b4..126152c 100644 --- a/monitor.py +++ b/monitor.py @@ -4,6 +4,8 @@ import time import logging import datetime import socket +import json +import os import requests import pydig @@ -62,7 +64,7 @@ def self_check(): try: if requests.get("https://google.com/").status_code != 200: return False - except ConnectionError: + except requests.exceptions.ConnectionError: return False return True @@ -72,7 +74,7 @@ def http_requirement(url: str, code: int) -> bool: for i in range(2): try: resp = requests.get(url) - except ConnectionError: + except requests.exceptions.ConnectionError: passed = False else: passed = resp.status_code == code @@ -140,4 +142,11 @@ monitors = { if __name__ == '__main__': # we assume this is gonna be run in a cron job as the gitpython # library is slowly leaking memory apparently + if os.path.exists("last-state"): + with open("last-state", 'r') as f: + last_states = json.load(f) + check(monitors) + + with open("last-state", 'w+') as f: + json.dump(last_states, f)