From 6cf37aebb2966ea99fb59c7b533e0305882affa5 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 1 Apr 2023 14:34:01 -0700 Subject: [PATCH] Add http get request to logger thread for passive monitoring This closes #1 --- clacksme/clacksme.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/clacksme/clacksme.py b/clacksme/clacksme.py index 7feb919..3977afb 100644 --- a/clacksme/clacksme.py +++ b/clacksme/clacksme.py @@ -4,6 +4,7 @@ import logging import signal import requests +from requests.exceptions import ConnectionError from multiprocessing import Process, Event, Queue from logging.handlers import QueueHandler from imapclient import IMAPClient, exceptions @@ -137,7 +138,7 @@ class MailboxNotifier(object): def shutdown_handler(signal, frame): _shtudown.set() -def logger_thread(log_queue): +def logger_thread(log_queue, url): logging.debug("starting logger thread") while True: entry = log_queue.get() @@ -146,6 +147,12 @@ def logger_thread(log_queue): break logger = logging.getLogger(entry.name) logger.handle(entry) + if url is not None: + try: + r = requests.get(url) + + except ConnectionError: + pass def event_thread(event_queue): logging.debug("starting event thread") @@ -177,6 +184,8 @@ def main(): db.init(args.store, pragmas={'journal_mode': 'wal'}) create_tables() + monitor_url = System.get_or_none(System.key == "monitor_url") + log_queue = Queue() event_queue = Queue() processes = [] @@ -191,7 +200,8 @@ def main(): logging.basicConfig(level=logging.DEBUG) logging.debug("starting up main") - log_thread = threading.Thread(target=logger_thread, args=(log_queue,)) + log_thread = threading.Thread(target=logger_thread, + args=(log_queue,monitor_url.value,)) log_thread.start() e_thread = threading.Thread(target=event_thread, args=(event_queue,)) e_thread.start()