11import logging
22import threading
3- from typing import List , Optional , Type , Dict , Set , Any
3+ from typing import List , Optional , Type
44
55import yaml
66
77import mongoose .core .cache as cache_module
88from mongoose .collect .nfstream_collector import NFStreamCollector
99from mongoose .collect .suricata_eve_collector import SuricataEveCollector
10+ from mongoose .core import Singleton
1011from mongoose .core .cache import SeverityCache
1112from mongoose .core .processing import ProcessingQueue
13+ from mongoose .core .registry import JobRegistry
1214from mongoose .core .sink import Sink
1315from mongoose .core .watchdogs import DropInConfigurationWatcher , DropInConfigurationHandler
1416from mongoose .enrich .base import Enrich
2123logger = logging .getLogger (__name__ )
2224
2325
24- class Singleton (type ):
25- _instances : Dict [type , type ] = {}
26-
27- def __call__ (cls , * args , ** kwargs ):
28- """Control instance creation to ensure singleton behavior.
29-
30- Args:
31- cls (type): The class being instantiated
32- *args: Positional arguments for class initialization
33- **kwargs: Keyword arguments for class initialization
34-
35- Returns:
36- type: The singleton instance of the class
37-
38- Note:
39- If an instance already exists, ``__init__`` will still be called with
40- the provided arguments, but no new instance is created.
41- """
42- if cls not in cls ._instances :
43- cls ._instances [cls ] = super (Singleton , cls ).__call__ (* args , ** kwargs )
44- return cls ._instances [cls ]
45-
46-
47- class JobRegistry (metaclass = Singleton ):
48- def __init__ (self ):
49- self .jobs : Set [Any ] = set ()
50-
51- def register (self , job : Any ):
52- self .jobs .add (job )
53-
54- def clear (self ):
55- self .jobs .clear ()
56-
57-
5826class Engine (metaclass = Singleton ):
5927 """
6028 The Engine class is responsible for loading the configuration,
@@ -78,9 +46,13 @@ def __init__(self, config_path: str, interface: str = None, watch_configuration_
7846 self .started = False
7947 self .thread_id = threading .get_ident ()
8048 self .watch_configuration_changes = watch_configuration_changes
81- self .webhook_configuration_watcher = DropInConfigurationWatcher (
82- self .config .extra_configuration_dir / "webhook.d" ,
83- DropInConfigurationHandler (WebhookForwarderConfiguration , self ._handle_webhook_configuration_changes ),
49+ self .webhook_configuration_watcher = (
50+ DropInConfigurationWatcher (
51+ self .config .extra_configuration_dir / "webhook.d" ,
52+ DropInConfigurationHandler (WebhookForwarderConfiguration , self ._handle_webhook_configuration_changes ),
53+ )
54+ if self .watch_configuration_changes
55+ else None
8456 )
8557
8658 def load_extra_config (self , name : str , config_class : Type ):
0 commit comments