prelude-correlator/master: Implement a plugin signaling method.

[email protected] Thu, 9 Jul 2009 17:57:27 +0200 (CEST)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit ddf3a07d34ebcb73d560c09af914faa9c343b9bd
Author: Yoann Vandoorselaere <[email protected]>
Date:   Wed Jun 24 13:11:12 2009 +0200

    Implement a plugin signaling method.
    
    Make it possible for plugin to define a 'signal' method that will
    get called when prelude-correlator handle a signal (can be used to
    perform special handling before exit, statistics or debugging purposes).


========================================

 PreludeCorrelator/main.py          |   10 ++++++----
 PreludeCorrelator/pluginmanager.py |   10 ++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

========================================

diff --git a/PreludeCorrelator/main.py b/PreludeCorrelator/main.py
index 717daa2..32c350d 100644
--- a/PreludeCorrelator/main.py
+++ b/PreludeCorrelator/main.py
@@ -31,6 +31,9 @@ class Env:
         def __init__(self):
                 self.logger = log.Log()
                 self.config = config.Config(siteconfig.conf_dir + '/prelude-correlator.conf')
+                self.pluginmanager = pluginmanager.PluginManager(self)
+
+                self.logger.info("%d plugin have been loaded." % (self.pluginmanager.getPluginCount()))
 
 
 class SignalHandler:
@@ -42,6 +45,8 @@ class SignalHandler:
 
         def _handle_signal(self, signum, frame):
                 self._env.logger.info("caught signal %d" % signum)
+                self._env.pluginmanager.signal(signum, frame)
+
                 if signum == signal.SIGQUIT:
                         self._env.prelude_client.stats()
                         context.stats(self._env.logger)
@@ -59,9 +64,6 @@ class PreludeClient:
                 self._continue = True
                 self._dry_run = dry_run
 
-                self._pm = pluginmanager.PluginManager(env)
-                self._env.logger.info("%d plugin have been loaded." % (self._pm.getPluginCount()))
-
                 self._client = ClientEasy("prelude-correlator", ClientEasy.PERMISSION_IDMEF_READ|ClientEasy.PERMISSION_IDMEF_WRITE,
                                           "Prelude-Correlator", "Correlator", "PreludeIDS Technologies",
                                           VERSION)
@@ -72,7 +74,7 @@ class PreludeClient:
                 if self._print_input:
                         self._print_input.write(str(idmef))
 
-                self._pm.run(idmef)
+                self._env.pluginmanager.run(idmef)
                 self._message_processed += 1
 
         def stats(self):
diff --git a/PreludeCorrelator/pluginmanager.py b/PreludeCorrelator/pluginmanager.py
index 1ac5749..8010335 100644
--- a/PreludeCorrelator/pluginmanager.py
+++ b/PreludeCorrelator/pluginmanager.py
@@ -30,6 +30,9 @@ class Plugin(object):
     def __init__(self, env):
         self.env = env
 
+    def signal(self, signo, frame):
+        pass
+
     def run(self, idmef):
         pass
 
@@ -61,6 +64,13 @@ class PluginManager:
     def getPluginCount(self):
         return self._count
 
+    def signal(self, signo, frame):
+        for plugin in self.__instances:
+            try:
+                plugin.signal(signo, frame)
+            except Exception, e:
+                traceback.print_exc()
+
     def run(self, idmef):
         for plugin in self.__instances:
             try:
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog