mirror of https://github.com/fail2ban/fail2ban
Added pyinotify backend
parent
e442503133
commit
d1050350db
|
@ -31,9 +31,7 @@ from failmanager import FailManagerEmpty
|
||||||
from filter import FileFilter
|
from filter import FileFilter
|
||||||
from mytime import MyTime
|
from mytime import MyTime
|
||||||
|
|
||||||
import time, logging, pyinotify
|
import time, logging, pyinotify
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban.filter")
|
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
|
# that matches a given regular expression. This class is instantiated by
|
||||||
# a Jail object.
|
# 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):
|
class FilterPyinotify(FileFilter):
|
||||||
|
##
|
||||||
# Constructor.
|
# Constructor.
|
||||||
#
|
#
|
||||||
# Initialize the filter object with default values.
|
# Initialize the filter object with default values.
|
||||||
# @param jail the jail object
|
# @param jail the jail object
|
||||||
|
|
||||||
def __init__(self, jail):
|
def __init__(self, jail):
|
||||||
FileFilter.__init__(self, jail)
|
FileFilter.__init__(self, jail)
|
||||||
self.__modified = False
|
self.__modified = False
|
||||||
|
# Pyinotify watch manager
|
||||||
self.monitor = pyinotify.WatchManager()
|
self.monitor = pyinotify.WatchManager()
|
||||||
self.watches = dict()
|
logSys.debug("Created FilterPyinotify")
|
||||||
|
|
||||||
|
|
||||||
def callback(self, path):
|
def callback(self, path):
|
||||||
|
@ -84,12 +73,12 @@ class FilterPyinotify(FileFilter):
|
||||||
# Add a log file path
|
# Add a log file path
|
||||||
#
|
#
|
||||||
# @param path log file path
|
# @param path log file path
|
||||||
|
|
||||||
def addLogPath(self, path, tail=False):
|
def addLogPath(self, path, tail=False):
|
||||||
if self.containsLogPath(path):
|
if self.containsLogPath(path):
|
||||||
logSys.error(path + " already exists")
|
logSys.error(path + " already exists")
|
||||||
else:
|
else:
|
||||||
wd = self.monitor.add_watch(path, pyinotify.IN_MODIFY)
|
wd = self.monitor.add_watch(path, pyinotify.IN_MODIFY)
|
||||||
self.watches[path] = wd[path]
|
|
||||||
FileFilter.addLogPath(self, path, tail)
|
FileFilter.addLogPath(self, path, tail)
|
||||||
logSys.info("Added logfile = %s" % path)
|
logSys.info("Added logfile = %s" % path)
|
||||||
|
|
||||||
|
@ -102,7 +91,6 @@ class FilterPyinotify(FileFilter):
|
||||||
if not self.containsLogPath(path):
|
if not self.containsLogPath(path):
|
||||||
logSys.error(path + " is not monitored")
|
logSys.error(path + " is not monitored")
|
||||||
else:
|
else:
|
||||||
self.monitor.rm_watch(self.watches[path])
|
|
||||||
FileFilter.delLogPath(self, path)
|
FileFilter.delLogPath(self, path)
|
||||||
logSys.info("Removed logfile = %s" % path)
|
logSys.info("Removed logfile = %s" % path)
|
||||||
|
|
||||||
|
@ -146,3 +134,15 @@ class FilterPyinotify(FileFilter):
|
||||||
def __cleanup(self):
|
def __cleanup(self):
|
||||||
del self.notifier
|
del self.notifier
|
||||||
del self.monitor
|
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)
|
||||||
|
|
Loading…
Reference in New Issue