monitor

Monitoring script
git clone git://git.bain.cz/monitor.git
Log | Files | Refs | README

commit b66b63e6bd6db8937bdcdc9c1cae48d18e19fd2d
parent b92cf90a0b29ec2b9d6eec984f2bfbbcbf78e782
Author: bain <bain@bain.cz>
Date:   Sun, 28 Nov 2021 00:26:55 +0100

make last state persistent, fix exceptions

Diffstat:
Mmonitor.py | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git 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)