Я пытаюсь сопоставить этот шаблон даты в fail2ban:
test.example.org 12.100.3.45 - - [14/Jun/2019:13:54:50 +0000] "GET
Можно использовать тестер регулярных выражений:
fail2ban-regex -d ^%%d/%%M/%%Y:%%H:%%M:%%S "test.example.org [14/Jun/2019:13:22:57 +0000] 1.2.3.4" "<HOST>"
Я ожидаю, что IP-адрес будет найден, но дата не найдена.
Running tests
=============
Use datepattern : {^%d/%M/%Y:%H:%M:%S}
Use failregex line : <HOST>
Use single line : test.example.org [14/Jun/2019:13:22:57 +0000] 1.2.3.4
Results
=======
Failregex: 0 total
Ignoreregex: 0 total
Date template hits:
Lines: 1 lines, 0 ignored, 0 matched, 1 missed
[processed in 0.00 sec]
|- Missed line(s):
| test.example.org [14/Jun/2019:13:22:57 +0000] 1.2.3.4
UPATE:
Я использую файл my.conf:
# fail2ban filter configuration for nginx proxy
# hk
[Definition]
failregex = ^<HOST> - [^-[ ]+.+HTTP/1.[0-9]" 401
ignoreregex =
datepattern = ^%%d/%%M/%%Y:%%H:%%M:%%S
При использовании такого шаблона даты я получаю сообщение об ошибке в анализаторе регулярных выражений.
Я понимаю, что fail2ban работает, беря datepattern и преобразовывая его в выражение регулярного выражения, которое ищет даты. Значит датапаттерн недействителен? Я верю в регулярное выражение (как указывает Шон в комментариях).
Running tests
=============
Use failregex filter file : nginx-proxy-auth, basedir: /etc/fail2ban
Use datepattern : ^Day/Minute/Year:24hour:Minute:Second
Use log file : /data/docker/nginx-proxy/logs/access.log
Use encoding : UTF-8
Traceback (most recent call last):
File "/usr/bin/fail2ban-regex", line 34, in <module>
exec_command_line()
File "/usr/lib/python3/dist-packages/fail2ban/client/fail2banregex.py", line 685, in exec_command_line
if not fail2banRegex.start(args):
File "/usr/lib/python3/dist-packages/fail2ban/client/fail2banregex.py", line 635, in start
self.process(test_lines)
File "/usr/lib/python3/dist-packages/fail2ban/client/fail2banregex.py", line 458, in process
line_datetimestripped, ret = self.testRegex(line)
File "/usr/lib/python3/dist-packages/fail2ban/client/fail2banregex.py", line 409, in testRegex
ret = self._filter.processLine(line, date)
File "/usr/lib/python3/dist-packages/fail2ban/server/filter.py", line 526, in processLine
(timeMatch, template) = self.dateDetector.matchTime(l)
File "/usr/lib/python3/dist-packages/fail2ban/server/datedetector.py", line 373, in matchTime
match = template.matchDate(line)
File "/usr/lib/python3/dist-packages/fail2ban/server/datetemplate.py", line 153, in matchDate
self._compileRegex()
File "/usr/lib/python3/dist-packages/fail2ban/server/datetemplate.py", line 147, in _compileRegex
raise e
File "/usr/lib/python3/dist-packages/fail2ban/server/datetemplate.py", line 144, in _compileRegex
self._cRegex = re.compile(self.regex)
File "/usr/lib/python3.6/re.py", line 233, in compile
return _compile(pattern, flags)
File "/usr/lib/python3.6/re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib/python3.6/sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "/usr/lib/python3.6/sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "/usr/lib/python3.6/sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "/usr/lib/python3.6/sre_parse.py", line 765, in _parse
p = _parse_sub(source, state, sub_verbose, nested + 1)
File "/usr/lib/python3.6/sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "/usr/lib/python3.6/sre_parse.py", line 759, in _parse
raise source.error(err.msg, len(name) + 1) from None
sre_constants.error: redefinition of group name 'M' as group 6; was group 3 at position 107
Таким образом, этот шаблон пытается найти minutes
вместо Months