Created OpenBSD mirror status checker

This commit is contained in:
Laura Nguyen 2021-08-19 17:00:55 -04:00
parent 6379fb4af5
commit 708579e0db
1 changed files with 15 additions and 0 deletions

15
main.py
View File

@ -18,6 +18,11 @@ def get_debian_dt(trace_file_url):
time_str = response_text.split('\n')[0]
return datetime.strptime(time_str, "%a %b %d %H:%M:%S UTC %Y")
def get_openbsd_sec(timestamp_file_url):
"""Get OpenBSD seconds since the Epoch from timestamp file"""
sec_str = requests.get(timestamp_file_url).text
return int(sec_str)
if __name__ == "__main__":
# Arch
try:
@ -44,3 +49,13 @@ if __name__ == "__main__":
print(OUTPUT.format("Debian"))
except requests.exceptions.RequestException as err:
print(ERROR.format("Debian", err))
# OpenBSD
try:
official_sec = get_openbsd_sec("https://ftp.openbsd.org/pub/OpenBSD/timestamp")
csc_sec = get_openbsd_sec(f"{CSC_MIRROR}OpenBSD/timestamp")
# Out-of-sync by 1 day maximum
OUTPUT = SUCCESS if official_sec < csc_sec + 86400 else FAILURE
print(OUTPUT.format("OpenBSD"))
except requests.exceptions.RequestException as err:
print(ERROR.format("OpenBSD", err))