From 2c8747cc76e88a58deb93d94fe39e51eaa9b8852 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Mon, 15 Jul 2013 18:40:32 +0100 Subject: [PATCH] BF: fail2ban-regex date detector template hits count now correct closes #295 --- fail2ban-regex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fail2ban-regex b/fail2ban-regex index 78716a43..e75cb2a3 100755 --- a/fail2ban-regex +++ b/fail2ban-regex @@ -46,6 +46,7 @@ from client.configparserinc import SafeConfigParserWithIncludes from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError from server.filter import Filter from server.failregex import RegexException +from server.datedetector import DateDetector from testcases.utils import FormatterWithTraceBack # Gets the instance of the logger. @@ -172,6 +173,8 @@ class Fail2banRegex(object): self._ignoreregex = list() self._failregex = list() self._line_stats = LineStats() + self._dateDetector = DateDetector() + self._dateDetector.addDefaultTemplate() def readRegex(self, value, regextype): @@ -256,6 +259,9 @@ class Fail2banRegex(object): if line.startswith('# ') or not line.strip(): # skip comment and empty lines continue + + self._dateDetector.matchTime(line) + is_ignored = fail2banRegex.testIgnoreRegex(line) if is_ignored: self._line_stats.ignored_lines.append(line) @@ -312,7 +318,7 @@ class Fail2banRegex(object): print "\nDate template hits:" out = [] - for template in self._filter.dateDetector.getTemplates(): + for template in self._dateDetector.getTemplates(): if self._verbose or template.getHits(): out.append("[%d] %s" % (template.getHits(), template.getName())) pprint_list(out, "[# of hits] date format")