From 54f4a7d2409dde5054ce692300022569db817ccf Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 5 Sep 2005 21:06:15 +0000 Subject: [PATCH] - Hopefully fixed bug #1256075 git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@187 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- logreader/logreader.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/logreader/logreader.py b/logreader/logreader.py index b1acf74a..37fe23a9 100644 --- a/logreader/logreader.py +++ b/logreader/logreader.py @@ -134,11 +134,13 @@ class LogReader: logSys.debug(self.logPath) logFile = self.openLogFile() self.setFilePos(logFile) - lastLine = '' + lastLine = None for line in logFile: + if not self.hasTime(line): + # There is no valid time in this line + continue lastLine = line - failList = self.findFailure(line) - for element in failList: + for element in self.findFailure(line): ip = element[0] unixTime = element[1] if unixTime < time.time()-self.findTime: @@ -152,7 +154,8 @@ class LogReader: else: ipList[ip] = (1, unixTime) self.lastPos = logFile.tell() - self.lastDate = self.getTime(lastLine) + if lastLine: + self.lastDate = self.getTime(lastLine) logFile.close() return ipList @@ -175,6 +178,15 @@ class LogReader: failList.append([ip, date]) return failList + def hasTime(self, line): + """ Return true if the line contains a date + """ + timeMatch = re.search(self.timeregex, line) + if timeMatch: + return True + else: + return False + def getTime(self, line): """ Gets the time of a log message. """