- Improved checking and logging output in findFailure

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@440 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 2006-10-31 22:24:34 +00:00
parent a49cc6bb08
commit 5baa08c86f
1 changed files with 27 additions and 16 deletions

View File

@ -30,7 +30,7 @@ from jailthread import JailThread
from datedetector import DateDetector from datedetector import DateDetector
from mytime import MyTime from mytime import MyTime
import logging, re import logging, re, sre_constants
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger("fail2ban.filter") logSys = logging.getLogger("fail2ban.filter")
@ -163,9 +163,12 @@ class Filter(JailThread):
# @param value the regular expression # @param value the regular expression
def setFailRegex(self, value): def setFailRegex(self, value):
self.__failRegex = value try:
self.__failRegexObj = re.compile(value) self.__failRegexObj = re.compile(value)
logSys.info("Set failregex = %s" % value) self.__failRegex = value
logSys.info("Set failregex = %s" % value)
except sre_constants.error:
logSys.error("Unable to compile regular expression " + value)
## ##
# Get the regular expression which matches the failure. # Get the regular expression which matches the failure.
@ -391,18 +394,26 @@ class Filter(JailThread):
def findFailure(self, line): def findFailure(self, line):
failList = list() failList = list()
match = self.__failRegexObj.search(line) if self.__failRegexObj == None:
if match: logSys.error("No failregex is set")
date = self.dateDetector.getUnixTime(match.string) else:
if not date == None: match = self.__failRegexObj.search(line)
try: if match:
ipMatch = DNSUtils.textToIp(match.group("host")) date = self.dateDetector.getUnixTime(match.string)
if ipMatch: if date == None:
for ip in ipMatch: logSys.debug("Found a match but no valid date/time found "
failList.append([ip, date]) + "for " + match.string + ". Please contact "
except IndexError: + "the author in order to get support for "
logSys.error("There is no 'host' group in the rule. " + + "this format")
"Please correct your configuration.") else:
try:
ipMatch = DNSUtils.textToIp(match.group("host"))
if ipMatch:
for ip in ipMatch:
failList.append([ip, date])
except IndexError:
logSys.error("There is no 'host' group in the rule. " +
"Please correct your configuration.")
return failList return failList