mirror of https://github.com/fail2ban/fail2ban
testSampleRegexsFactory: `time` is not mandatory anymore (check time only if set in json), allows usage of same line(s) matching different `logtype` option:
`# filterOptions: [{"logtype": "file"}, {"logtype": "short"}, {"logtype": "journal"}]`pull/2630/head
parent
8dc6f30cdd
commit
9e6d07d928
|
@ -223,11 +223,9 @@ def testSampleRegexsFactory(name, basedir):
|
||||||
try:
|
try:
|
||||||
fail = {}
|
fail = {}
|
||||||
# for logtype "journal" we don't need parse timestamp (simulate real systemd-backend handling):
|
# for logtype "journal" we don't need parse timestamp (simulate real systemd-backend handling):
|
||||||
checktime = True
|
|
||||||
if opts.get('logtype') != 'journal':
|
if opts.get('logtype') != 'journal':
|
||||||
ret = flt.processLine(line)
|
ret = flt.processLine(line)
|
||||||
else: # simulate journal processing, time is known from journal (formatJournalEntry):
|
else: # simulate journal processing, time is known from journal (formatJournalEntry):
|
||||||
checktime = False
|
|
||||||
if opts.get('test.prefix-line'): # journal backends creates common prefix-line:
|
if opts.get('test.prefix-line'): # journal backends creates common prefix-line:
|
||||||
line = opts.get('test.prefix-line') + line
|
line = opts.get('test.prefix-line') + line
|
||||||
ret = flt.processLine(('', TEST_NOW_STR, line.rstrip('\r\n')), TEST_NOW)
|
ret = flt.processLine(('', TEST_NOW_STR, line.rstrip('\r\n')), TEST_NOW)
|
||||||
|
@ -271,7 +269,7 @@ def testSampleRegexsFactory(name, basedir):
|
||||||
self.assertEqual(fv, v)
|
self.assertEqual(fv, v)
|
||||||
|
|
||||||
t = faildata.get("time", None)
|
t = faildata.get("time", None)
|
||||||
if checktime or t is not None:
|
if t is not None:
|
||||||
try:
|
try:
|
||||||
jsonTimeLocal = datetime.datetime.strptime(t, "%Y-%m-%dT%H:%M:%S")
|
jsonTimeLocal = datetime.datetime.strptime(t, "%Y-%m-%dT%H:%M:%S")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
Loading…
Reference in New Issue