]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
suricata-reporter: Create a couple of worker processes
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Aug 2025 14:18:15 +0000 (15:18 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Sep 2025 17:42:00 +0000 (18:42 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/suricata/suricata-reporter

index b23f7e5d832eef484818e9e3ece97ce5d494e420..0e8d89b654a19b9d2107164c5aaafdcecbe896e7 100644 (file)
@@ -23,8 +23,10 @@ import argparse
 import asyncio
 import logging
 import logging.handlers
+import multiprocessing
 import signal
 import sys
+import time
 
 log = logging.getLogger("suricata-reporter")
 log.setLevel(logging.DEBUG)
@@ -34,7 +36,13 @@ class Reporter(object):
                This is the main class that handles all the things...
        """
        def __init__(self):
-               pass
+               # Fetch CPU count
+               cpu_count = multiprocessing.cpu_count()
+
+               # Create as many workers as we have processors
+               self.workers = [
+                       Worker(reporter=self) for _ in range(cpu_count)
+               ]
 
        async def run(self):
                """
@@ -42,13 +50,45 @@ class Reporter(object):
                """
                log.debug("Starting reporter...")
 
+               # Start all workers
+               for worker in self.workers:
+                       worker.start()
+
                # Sleep for forever
                while True:
                        await asyncio.sleep(1)
 
+               # Terminate all workers
+               for worker in self.workers:
+                       worker.terminate()
+
+               # Wait until all workers have terminated
+               for worker in self.workers:
+                       worker.join()
+
                log.debug("Reporter has exited")
 
 
+class Worker(multiprocessing.Process):
+       def __init__(self, reporter):
+               super().__init__()
+
+               # Store the reporter
+               self.reporter = reporter
+
+       def run(self):
+               """
+                       This is the main entry point for workers...
+               """
+               log.debug("Worker %s launched" % self.pid)
+
+               # Sleep for forever
+               while True:
+                       time.sleep(1)
+
+               log.debug("Worker %s terminated" % self.pid)
+
+
 def setup_logging(loglevel=logging.INFO):
        log.setLevel(loglevel)