From: Michael Tremer Date: Tue, 5 Aug 2025 14:25:04 +0000 (+0100) Subject: suricata-reporter: Create a queue we can push events into the workers with X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d95a1ee37e514a2efa706ece609b0aeb117e249a;p=ipfire-2.x.git suricata-reporter: Create a queue we can push events into the workers with Signed-off-by: Michael Tremer --- diff --git a/config/suricata/suricata-reporter b/config/suricata/suricata-reporter index 0e8d89b65..e8ab952f8 100644 --- a/config/suricata/suricata-reporter +++ b/config/suricata/suricata-reporter @@ -26,7 +26,6 @@ import logging.handlers import multiprocessing import signal import sys -import time log = logging.getLogger("suricata-reporter") log.setLevel(logging.DEBUG) @@ -39,6 +38,9 @@ class Reporter(object): # Fetch CPU count cpu_count = multiprocessing.cpu_count() + # Create an events queue + self.queue = multiprocessing.Queue(1024) + # Create as many workers as we have processors self.workers = [ Worker(reporter=self) for _ in range(cpu_count) @@ -58,6 +60,9 @@ class Reporter(object): while True: await asyncio.sleep(1) + # Write some data into the queue + self.queue.put("ABC", block=False) + # Terminate all workers for worker in self.workers: worker.terminate() @@ -82,9 +87,12 @@ class Worker(multiprocessing.Process): """ log.debug("Worker %s launched" % self.pid) - # Sleep for forever + # Loop for forever while True: - time.sleep(1) + event = self.reporter.queue.get(block=True) + + # Log the event + log.debug("Received event in worker %s: %s" % (self.pid, event)) log.debug("Worker %s terminated" % self.pid)