Skip to content

Improve regex pattern for parsing ban entries#14

Merged
giftkugel merged 1 commit intowebishdev:mainfrom
gentges:patch-1
Apr 18, 2026
Merged

Improve regex pattern for parsing ban entries#14
giftkugel merged 1 commit intowebishdev:mainfrom
gentges:patch-1

Conversation

@gentges
Copy link
Copy Markdown
Contributor

@gentges gentges commented Apr 17, 2026

Thank you for building this tool I really appreciate it!

While I was trying to fix some connection issues on my server I also looked at the container logs running this image and I noticed a lot of entries like this one:

2026/04/17 20:36:28.885895 fail2ban-client.go:257: [Error] GetBanned: Failed to parse ban entry: 111.22.33.4 2026-04-16 12:43:13 + -1 = 9999-12-31 23:59:59

These were coming from my ufw rule, but when I fetched the banned ips for another rule I got a similar looking entry:

1.2.3.4 2026-04-17 14:28:20 + 3600 = 2026-04-17 15:28:20

Both of these ban entries would not match the regex before the error position.
I updated the regex to allow for multiple spaces and/or tabs after the ip address and also allow for negative numbers in the duration.

Adjusted the whitespace handling in the first part of the regex and allowed for negative numbers in the ban duration part.
Copilot AI review requested due to automatic review settings April 17, 2026 20:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the ban-entry parsing logic in GetBanned to better match the actual fail2ban-client --with-time output seen in logs, reducing “Failed to parse ban entry” errors.

Changes:

  • Updated the ban-entry regex to accept multiple spaces/tabs after the IP address.
  • Updated the ban-entry regex to accept negative duration values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fail2ban-client/fail2ban-client.go
@giftkugel
Copy link
Copy Markdown
Member

Thank you for the contribution @gentges 😄

@giftkugel giftkugel merged commit 5f31b45 into webishdev:main Apr 18, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants