Add http get request to logger thread for passive monitoring

This closes #1
This commit is contained in:
Morgan McMillian 2023-04-01 14:34:01 -07:00
parent cb914671d2
commit 6cf37aebb2

View file

@ -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()