diff --git a/server/datedetector.py b/server/datedetector.py index faf9f45f..7301ec91 100644 --- a/server/datedetector.py +++ b/server/datedetector.py @@ -117,6 +117,12 @@ class DateDetector: template.setRegex("\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}") template.setPattern("%d-%m-%Y %H:%M:%S") self.__templates.append(template) + # 01-27-2012 16:22:44.252 + template = DateStrptime() + template.setName("Month-Day-Year Hour:Minute:Second[.Millisecond]") + template.setRegex("\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}") + template.setPattern("%m-%d-%Y %H:%M:%S") + self.__templates.append(template) # TAI64N template = DateTai64n() template.setName("TAI64N") diff --git a/server/datetemplate.py b/server/datetemplate.py index ddf7dc82..f663862e 100644 --- a/server/datetemplate.py +++ b/server/datetemplate.py @@ -140,12 +140,22 @@ class DateStrptime(DateTemplate): conv = self.convertLocale(dateMatch.group()) try: date = list(time.strptime(conv, self.getPattern())) - except ValueError, e: + except (ValueError, re.error), e: # Try to add the current year to the pattern. Should fix # the "Feb 29" issue. - conv += " %s" % MyTime.gmtime()[0] - pattern = "%s %%Y" % self.getPattern() - date = list(time.strptime(conv, pattern)) + opattern = self.getPattern() + # makes sense only if %Y is not in already: + if not '%Y' in opattern: + pattern = "%s %%Y" % opattern + conv += " %s" % MyTime.gmtime()[0] + date = list(time.strptime(conv, pattern)) + else: + # we are helpless here + raise ValueError( + "Given pattern %r does not match. Original " + "exception was %r and Feb 29 workaround could not " + "be tested due to already present year mark in the " + "pattern" % (opattern, e)) if date[0] < 2000: # There is probably no year field in the logs date[0] = MyTime.gmtime()[0] diff --git a/testcases/datedetectortestcase.py b/testcases/datedetectortestcase.py index e6f690ad..1f73cd1e 100644 --- a/testcases/datedetectortestcase.py +++ b/testcases/datedetectortestcase.py @@ -67,6 +67,7 @@ class DateDetectorTest(unittest.TestCase): "Jan 23 21:59:59", "2005.01.23 21:59:59", "23/01/2005 21:59:59", + "01-23-2005 21:59:59.252", # reported on f2b, causes Feb29 fix to break ): log = sdate + "[sshd] error: PAM: Authentication failure" # exclude