- Fixed a bug in user defined regex/pattern date template

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@460 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 2006-11-12 21:57:26 +00:00
parent 2995a99596
commit b3143c723d
3 changed files with 16 additions and 6 deletions

View File

@ -26,7 +26,6 @@ __license__ = "GPL"
import time, logging import time, logging
from datetemplate import DateTemplate
from datestrptime import DateStrptime from datestrptime import DateStrptime
from datetai64n import DateTai64n from datetai64n import DateTai64n
from dateepoch import DateEpoch from dateepoch import DateEpoch
@ -40,7 +39,7 @@ class DateDetector:
def __init__(self): def __init__(self):
self.__lock = Lock() self.__lock = Lock()
self.__templates = list() self.__templates = list()
self.__defTemplate = DateTemplate() self.__defTemplate = DateStrptime()
def addDefaultTemplate(self): def addDefaultTemplate(self):
# standard # standard

View File

@ -42,14 +42,14 @@ class DateTemplate:
return self.__name return self.__name
def setRegex(self, regex): def setRegex(self, regex):
self.__regex = regex self.__regex = regex.strip()
self.__cRegex = re.compile(regex) self.__cRegex = re.compile(regex)
def getRegex(self): def getRegex(self):
return self.__regex return self.__regex
def setPattern(self, pattern): def setPattern(self, pattern):
self.__pattern = pattern self.__pattern = pattern.strip()
def getPattern(self): def getPattern(self):
return self.__pattern return self.__pattern

View File

@ -24,7 +24,7 @@ __date__ = "$Date: 2006-07-17 00:21:58 +0200 (Mon, 17 Jul 2006) $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL" __license__ = "GPL"
import unittest, time import unittest
from server.datedetector import DateDetector from server.datedetector import DateDetector
from server.datetemplate import DateTemplate from server.datetemplate import DateTemplate
@ -54,3 +54,14 @@ class DateDetectorTest(unittest.TestCase):
self.assertEqual(self.__datedetector.getTime(log), date) self.assertEqual(self.__datedetector.getTime(log), date)
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix) self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)
def testDefaultTempate(self):
self.__datedetector.setDefaultRegex("^\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}")
self.__datedetector.setDefaultPattern("%b %d %H:%M:%S")
log = "Jan 23 21:59:59 [sshd] error: PAM: Authentication failure"
date = [2005, 1, 23, 21, 59, 59, 1, 23, -1]
dateUnix = 1106513999.0
self.assertEqual(self.__datedetector.getTime(log), date)
self.assertEqual(self.__datedetector.getUnixTime(log), dateUnix)