From cdf008ed7040e0640161092597e10185505b2ec3 Mon Sep 17 00:00:00 2001 From: NullRien Date: Fri, 6 Dec 2024 10:56:55 +0000 Subject: [PATCH 1/4] Update checks.yaml Changed amazonaws.com to amazonaws.net because of some weird ping error (and also to still show the failed message) --- checks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks.yaml b/checks.yaml index cb268922..e8fac345 100644 --- a/checks.yaml +++ b/checks.yaml @@ -40,7 +40,7 @@ - name: Dummy Postgres Database type: port - host: ec2-54-173-89-248.compute-1.amazonaws.com + host: ec2-54-173-89-228.compute-1.amazonaws.net port: 5432 - name: Dummy MySQL Database From cafaf32f3e6b736857ac71349100fbbf6f6c1203 Mon Sep 17 00:00:00 2001 From: NullRien Date: Fri, 6 Dec 2024 10:58:15 +0000 Subject: [PATCH 2/4] Update tinystatus.py Small formatting changes added a get_missing_files function (if you want to quickly update to the latest files or accidentally deleted one or 2 like me) --- tinystatus.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tinystatus.py b/tinystatus.py index 327ff76a..b55cf4a6 100644 --- a/tinystatus.py +++ b/tinystatus.py @@ -13,24 +13,28 @@ import logging import platform + # Load environment variables load_dotenv() + # Configuration MONITOR_CONTINOUSLY = os.getenv('MONITOR_CONTINOUSLY', 'True') == 'True' CHECK_INTERVAL = int(os.getenv('CHECK_INTERVAL', 30)) MAX_HISTORY_ENTRIES = int(os.getenv('MAX_HISTORY_ENTRIES', 100)) LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO') -CHECKS_FILE = os.getenv('CHECKS_FILE', 'checks.yaml') +CHECKS_FILE = os.getenv('CHECKS_FILE', "checks.yaml") INCIDENTS_FILE = os.getenv('INCIDENTS_FILE', 'incidents.md') TEMPLATE_FILE = os.getenv('TEMPLATE_FILE', 'index.html.theme') HISTORY_TEMPLATE_FILE = os.getenv('HISTORY_TEMPLATE_FILE', 'history.html.theme') STATUS_HISTORY_FILE = os.getenv('STATUS_HISTORY_FILE', 'history.json') -HTML_OUTPUT_DIRECTORY = os.getenv('HTML_OUTPUT_DIRECTORY', os.getcwd()) +HTML_OUTPUT_DIRECTORY = os.getenv('HTML_OUTPUT_DIRECTORY',f"{os.getcwd()}/web") + # Platform Idendifier PLATFORM = platform.system().lower() + # Service check functions async def check_http(url, expected_code, selfsigned): async with aiohttp.ClientSession() as session: @@ -119,10 +123,38 @@ def update_history(results): save_history(history) +async def download_file(url, filename): + async with aiohttp.ClientSession() as session: + print(f"Starting download file from {url}") + async with session.get(url) as response: + assert response.status == 200 + with open(filename, "wb") as f: + while True: + chunk = await response.content.readany() + if not chunk: + break + f.write(chunk) + print(f"Downloaded {filename} from {url}") + + +async def get_missing_files(): + # Downloads (latest version of) missing files + if not os.path.exists(CHECKS_FILE): + await download_file("https://raw.githubusercontent.com/harsxv/tinystatus/refs/heads/master/checks.yaml", CHECKS_FILE) + if not os.path.exists(INCIDENTS_FILE): + await download_file("https://raw.githubusercontent.com/harsxv/tinystatus/refs/heads/master/incidents.md", INCIDENTS_FILE) + if not os.path.exists(TEMPLATE_FILE): + await download_file("https://raw.githubusercontent.com/harsxv/tinystatus/refs/heads/master/index.html.theme", TEMPLATE_FILE) + if not os.path.exists(HISTORY_TEMPLATE_FILE): + await download_file("https://raw.githubusercontent.com/harsxv/tinystatus/refs/heads/master/history.html.theme", HISTORY_TEMPLATE_FILE) + + # Main monitoring loop async def monitor_services(): os.makedirs(HTML_OUTPUT_DIRECTORY, exist_ok=True) + await get_missing_files() + while True: start_ts = time.monotonic() down_services = [] From d4d0e8925939fb37dbce263c8aa933d8f835134d Mon Sep 17 00:00:00 2001 From: NullRien Date: Fri, 6 Dec 2024 11:15:58 +0000 Subject: [PATCH 3/4] Update tinystatus.py Fixed bug and added one new line, crazy right --- tinystatus.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tinystatus.py b/tinystatus.py index b55cf4a6..7c3eb03e 100644 --- a/tinystatus.py +++ b/tinystatus.py @@ -101,7 +101,10 @@ async def run_checks(checks): def load_history(): if os.path.exists(STATUS_HISTORY_FILE): with open(STATUS_HISTORY_FILE, 'r') as f: - return json.load(f) + try: + return json.load(f) + except json.JSONDecodeError: + return {} return {} @@ -222,6 +225,7 @@ def main(): with open(os.path.join(HTML_OUTPUT_DIRECTORY, 'index.html'), 'w') as f: f.write(html) + if __name__ == "__main__": logging.basicConfig(level=getattr(logging, LOG_LEVEL), format='%(asctime)s - %(levelname)s - %(message)s') asyncio.run(monitor_services()) From ad147ae54986622a57235fa2a46bb7e98d89af92 Mon Sep 17 00:00:00 2001 From: NullRien Date: Fri, 6 Dec 2024 11:18:27 +0000 Subject: [PATCH 4/4] Update tinystatus.py removed the double quotes i added for some reason? --- tinystatus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinystatus.py b/tinystatus.py index 7c3eb03e..95ef784d 100644 --- a/tinystatus.py +++ b/tinystatus.py @@ -23,7 +23,7 @@ CHECK_INTERVAL = int(os.getenv('CHECK_INTERVAL', 30)) MAX_HISTORY_ENTRIES = int(os.getenv('MAX_HISTORY_ENTRIES', 100)) LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO') -CHECKS_FILE = os.getenv('CHECKS_FILE', "checks.yaml") +CHECKS_FILE = os.getenv('CHECKS_FILE', 'checks.yaml') INCIDENTS_FILE = os.getenv('INCIDENTS_FILE', 'incidents.md') TEMPLATE_FILE = os.getenv('TEMPLATE_FILE', 'index.html.theme') HISTORY_TEMPLATE_FILE = os.getenv('HISTORY_TEMPLATE_FILE', 'history.html.theme')