/usr/share/pyshared/PreludeCorrelator/pluginmanager.py is in prelude-correlator 1.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | # Copyright (C) 2009 PreludeIDS Technologies. All Rights Reserved.
# Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
#
# This file is part of the Prelude-Correlator program.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
import pkg_resources, sys, os, traceback, ConfigParser
class PluginLog:
def __init__(self, env):
self.__logger = env.logger
self.__prefix = "[" + self.__class__.__name__ + "]: "
def debug(self, log):
self.__logger.debug(self.__prefix + log)
def info(self, log):
self.__logger.info(self.__prefix + log)
def warning(self, log):
self.__logger.warning(self.__prefix + log)
def error(self, log):
self.__logger.error(self.__prefix + log)
def critical(self, log):
self.__logger.critical(self.__prefix + log)
class Plugin(object, PluginLog):
enable = True
def getConfigValue(self, option, default=None, type=str):
return self.env.config.get(self.__class__.__name__, option, default=default, type=type)
def __init__(self, env):
self.env = env
PluginLog.__init__(self, env)
def signal(self, signo, frame):
pass
def run(self, idmef):
pass
class PluginManager:
__ENTRYPOINT = 'PreludeCorrelator.plugins'
def __init__(self, env):
self._count = 0
self.__instances = []
for entrypoint in pkg_resources.iter_entry_points(self.__ENTRYPOINT):
try:
plugin_class = entrypoint.load()
except Exception, e:
env.logger.warning("%s: %s" % (entrypoint, e))
continue
pname = plugin_class.__name__
if env.config.getAsBool(pname, "disable", default=False) is True:
env.logger.info("[%s]: disabled on user request" % (pname))
continue
try:
pi = plugin_class(env)
except Exception, e:
env.logger.warning("[%s]: exception occurred while loading: %s" % (pname, e))
continue
self.__instances.append(pi)
self._count += 1
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:
plugin.run(idmef)
except Exception, e:
traceback.print_exc()
|