make last state persistent, fix exceptions
This commit is contained in:
parent
b92cf90a0b
commit
b66b63e6bd
1 changed files with 11 additions and 2 deletions
13
monitor.py
13
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)
|
||||
|
|
Loading…
Reference in a new issue