Repository navigation
filter.d/nginx-botsearch: support the journal log format - #4223
Merged
Merged
Conversation
The error-log regex hardcoded the file-format prefix, so lines carrying a systemd journal prefix were missed. Use __prefix_line from nginx-error-common.conf, as the other nginx error-log filters already do. Closes gh-3732
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nginx-botsearchmisses every error-log line when nginx logs to the systemd journal, because its regex hardcodes the file-format prefix:The plain file format still matches with the default
logtype=file,1 matched, 0 missedbefore and after.The fix
nginx-error-common.confand%(__prefix_line)s, which is exactly what gh-3646 (commite03df480) did fornginx-forbidden,nginx-http-authandnginx-limit-req.nginx-botsearchwas simply left out of that pass.On the other filter in the issue
gh-3732 names both
nginx-bad-request.confandnginx-botsearch.conf. I only changed the latter, deliberately:nginx-bad-requestmatches the access log (^<HOST> - \S+ \[\] "[^"]*" 400), which has no error-log prefix to parameterise, so__prefix_linedoes not apply to it. If you want journal support there it is a different change and I did not want to bundle a guess with a verified fix.Verification
Two journal-format lines added to
fail2ban/tests/files/logs/nginx-botsearchunder# filterOptions: [{"logtype": "journal"}].They are not invented. They are the file-format sample lines already in that file, re-prefixed with
host nginx[2833]:, the same convention upstream used innginx-http-auth:22andnginx-limit-req:29.With the filter change stashed and the new lines in place:
Restored:
fail2ban-testcases --no-network samplesis 100 tests OK, and the full run is 541 tests OK (27 skipped, missing optional modules).Disclosure: written with AI assistance (Claude Code). I ran fail2ban-regex for both logtypes myself, confirmed the file format still matches, and checked the journal prefix convention against the lines upstream already added.