From d1050350db96703cf15a36c99f842e45623d17e5 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Fri, 30 Dec 2011 00:28:17 -0500 Subject: [PATCH] Added pyinotify backend --- server/filterpyinotify.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/server/filterpyinotify.py b/server/filterpyinotify.py index c5e70e220..9b7a6f096 100644 --- a/server/filterpyinotify.py +++ b/server/filterpyinotify.py @@ -31,9 +31,7 @@ from failmanager import FailManagerEmpty from filter import FileFilter from mytime import MyTime -import time, logging, pyinotify - - +import time, logging, pyinotify # Gets the instance of the logger. logSys = logging.getLogger("fail2ban.filter") @@ -45,28 +43,19 @@ logSys = logging.getLogger("fail2ban.filter") # that matches a given regular expression. This class is instantiated by # a Jail object. -class ProcessPyinotify(pyinotify.ProcessEvent): - def __init__(self, FileFilter, **kargs): - super(ProcessPyinotify, self).__init__(**kargs) - self.__FileFilter = FileFilter - pass - - # just need default, since using mask on watch to limit events - def process_default(self, event): - logSys.debug("PYINOTIFY: Callback for Event: %s" % event) - self.__FileFilter.callback(event.pathname) - - class FilterPyinotify(FileFilter): + ## # Constructor. # # Initialize the filter object with default values. # @param jail the jail object + def __init__(self, jail): FileFilter.__init__(self, jail) self.__modified = False + # Pyinotify watch manager self.monitor = pyinotify.WatchManager() - self.watches = dict() + logSys.debug("Created FilterPyinotify") def callback(self, path): @@ -84,12 +73,12 @@ class FilterPyinotify(FileFilter): # Add a log file path # # @param path log file path + def addLogPath(self, path, tail=False): if self.containsLogPath(path): logSys.error(path + " already exists") else: wd = self.monitor.add_watch(path, pyinotify.IN_MODIFY) - self.watches[path] = wd[path] FileFilter.addLogPath(self, path, tail) logSys.info("Added logfile = %s" % path) @@ -102,7 +91,6 @@ class FilterPyinotify(FileFilter): if not self.containsLogPath(path): logSys.error(path + " is not monitored") else: - self.monitor.rm_watch(self.watches[path]) FileFilter.delLogPath(self, path) logSys.info("Removed logfile = %s" % path) @@ -146,3 +134,15 @@ class FilterPyinotify(FileFilter): def __cleanup(self): del self.notifier del self.monitor + + +class ProcessPyinotify(pyinotify.ProcessEvent): + def __init__(self, FileFilter, **kargs): + super(ProcessPyinotify, self).__init__(**kargs) + self.__FileFilter = FileFilter + pass + + # just need default, since using mask on watch to limit events + def process_default(self, event): + logSys.debug("PYINOTIFY: Callback for Event: %s" % event) + self.__FileFilter.callback(event.pathname)