mirror of https://github.com/fail2ban/fail2ban
ENH: Allow setting of date pattern as part of filter config Init section
parent
614fb8505e
commit
7c3a2a0223
|
@ -56,6 +56,8 @@ class FilterReader(DefinitionInitConfigReader):
|
||||||
if self._initOpts:
|
if self._initOpts:
|
||||||
if 'maxlines' in self._initOpts:
|
if 'maxlines' in self._initOpts:
|
||||||
stream.append(["set", self._jailName, "maxlines", self._initOpts["maxlines"]])
|
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.
|
# Do not send a command if the match is empty.
|
||||||
if self._initOpts.get("journalmatch", '') != '':
|
if self._initOpts.get("journalmatch", '') != '':
|
||||||
for match in self._initOpts["journalmatch"].split("\n"):
|
for match in self._initOpts["journalmatch"].split("\n"):
|
||||||
|
|
|
@ -201,6 +201,7 @@ class FilterReaderTest(unittest.TestCase):
|
||||||
"_COMM=sshd", "+", "_SYSTEMD_UNIT=sshd.service", "_UID=0"],
|
"_COMM=sshd", "+", "_SYSTEMD_UNIT=sshd.service", "_UID=0"],
|
||||||
['set', 'testcase01', 'addjournalmatch',
|
['set', 'testcase01', 'addjournalmatch',
|
||||||
"FIELD= with spaces ", "+", "AFIELD= with + char and spaces"],
|
"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
|
['set', 'testcase01', 'maxlines', "1"], # Last for overide test
|
||||||
]
|
]
|
||||||
filterReader = FilterReader("testcase01", "testcase01", {})
|
filterReader = FilterReader("testcase01", "testcase01", {})
|
||||||
|
|
|
@ -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" is number of log lines to buffer for multi-line regex searches
|
||||||
maxlines = 1
|
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
|
# Option: journalmatch
|
||||||
# Notes.: systemd journalctl style match filter for journal based backends
|
# Notes.: systemd journalctl style match filter for journal based backends
|
||||||
# Values: TEXT
|
# Values: TEXT
|
||||||
|
|
Loading…
Reference in New Issue