ENH: FilterPoll -- adjusted some msgs + allowed to operate without jail (for testing)

pull/8/merge
Yaroslav Halchenko 2012-07-19 01:08:34 -04:00
parent 42523dce92
commit b3614d4ea2
1 changed files with 24 additions and 19 deletions

View File

@ -17,14 +17,13 @@
# along with Fail2Ban; if not, write to the Free Software # along with Fail2Ban; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Author: Cyril Jaquier # Author: Cyril Jaquier, Yaroslav Halchenko
# #
# $Revision$
__author__ = "Cyril Jaquier" __author__ = "Cyril Jaquier, Yaroslav Halchenko"
__version__ = "$Revision$" __version__ = "$Revision$"
__date__ = "$Date$" __date__ = "$Date$"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier; 2012 Yaroslav Halchenko"
__license__ = "GPL" __license__ = "GPL"
from failmanager import FailManagerEmpty from failmanager import FailManagerEmpty
@ -100,8 +99,9 @@ class FilterPoll(FileFilter):
if not self.getIdle(): if not self.getIdle():
# Get file modification # Get file modification
for container in self.getLogPath(): for container in self.getLogPath():
if self.isModified(container.getFileName()): filename = container.getFileName()
self.getFailures(container.getFileName()) if self.isModified(filename):
self.getFailures(filename)
self.__modified = True self.__modified = True
if self.__modified: if self.__modified:
@ -116,7 +116,8 @@ class FilterPoll(FileFilter):
time.sleep(self.getSleepTime()) time.sleep(self.getSleepTime())
else: else:
time.sleep(self.getSleepTime()) time.sleep(self.getSleepTime())
logSys.debug(self.jail.getName() + ": filter terminated") logSys.debug((self.jail and self.jail.getName() or "jailless") +
" filter terminated")
return True return True
## ##
@ -135,11 +136,15 @@ class FilterPoll(FileFilter):
logSys.debug(filename + " has been modified") logSys.debug(filename + " has been modified")
self.__lastModTime[filename] = logStats.st_mtime self.__lastModTime[filename] = logStats.st_mtime
return True return True
except OSError: except OSError, e:
logSys.error("Unable to get stat on " + filename) logSys.error("Unable to get stat on %s because of: %s"
self.__file404Cnt[filename] = self.__file404Cnt[filename] + 1 % (filename, e))
self.__file404Cnt[filename] += 1
if self.__file404Cnt[filename] > 2: if self.__file404Cnt[filename] > 2:
logSys.warn("Too much read error. Set the jail idle") logSys.warn("Too many errors. Setting the jail idle")
self.jail.setIdle(True) if self.jail:
self.jail.setIdle(True)
else:
logSys.warn("No jail is assigned to %s" % self)
self.__file404Cnt[filename] = 0 self.__file404Cnt[filename] = 0
return False return False