From 7c3a2a022338926e3fa695754e0cc560405a6b50 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Wed, 17 Jul 2013 21:27:19 +0100 Subject: [PATCH] ENH: Allow setting of date pattern as part of filter config Init section --- fail2ban/client/filterreader.py | 2 ++ fail2ban/tests/clientreadertestcase.py | 1 + fail2ban/tests/files/filter.d/testcase01.conf | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/fail2ban/client/filterreader.py b/fail2ban/client/filterreader.py index e5fe8f4f..d8a6dbe8 100644 --- a/fail2ban/client/filterreader.py +++ b/fail2ban/client/filterreader.py @@ -56,6 +56,8 @@ class FilterReader(DefinitionInitConfigReader): if self._initOpts: if 'maxlines' in self._initOpts: stream.append(["set", self._jailName, "maxlines", self._initOpts["maxlines"]]) + if 'datepattern' in self._initOpts: + stream.append(["set", self._jailName, "datepattern", self._initOpts["datepattern"]]) # Do not send a command if the match is empty. if self._initOpts.get("journalmatch", '') != '': for match in self._initOpts["journalmatch"].split("\n"): diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 9095a4af..30138d43 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -201,6 +201,7 @@ class FilterReaderTest(unittest.TestCase): "_COMM=sshd", "+", "_SYSTEMD_UNIT=sshd.service", "_UID=0"], ['set', 'testcase01', 'addjournalmatch', "FIELD= with spaces ", "+", "AFIELD= with + char and spaces"], + ['set', 'testcase01', 'datepattern', "%Y %m %d %H:%M:%S"], ['set', 'testcase01', 'maxlines', "1"], # Last for overide test ] filterReader = FilterReader("testcase01", "testcase01", {}) diff --git a/fail2ban/tests/files/filter.d/testcase01.conf b/fail2ban/tests/files/filter.d/testcase01.conf index 8bc4261d..0dbbbd2a 100644 --- a/fail2ban/tests/files/filter.d/testcase01.conf +++ b/fail2ban/tests/files/filter.d/testcase01.conf @@ -37,6 +37,12 @@ ignoreregex = ^.+ john from host 192.168.1.1\s*$ # "maxlines" is number of log lines to buffer for multi-line regex searches maxlines = 1 +# "datepattern" allows setting of a custom data pattern as alternative +# to the default date detectors. See manpage strptime(3) for date formats. +# NOTE: that ALL '%' must be prefixed with '%' due to string substitution +# e.g. %%Y-%%m-%%d %%H:%%M +datepattern = %%Y %%m %%d %%H:%%M:%%S + # Option: journalmatch # Notes.: systemd journalctl style match filter for journal based backends # Values: TEXT