Fail2ban does not perform regex on odoo log
I have installed fail2ban with odoo 13.
Below are my configuration and sample output, but I cant seem to figure out why it does not filter.
user@tempdev:/etc/fail2ban# fail2ban-regex -v /var/log/odoo/odoo.log /etc/fail2ban/filter.d/odoo-login.conf
Running tests
=============
Use failregex filter file : odoo-login, basedir: /etc/fail2ban
Use log file : /var/log/odoo/odoo.log
Use encoding : UTF-8
Results
=======
Failregex: 0 total
|- #) [# of hits] regular expression
| 1) [0] ^\d+ INFO \S+ \S+ Login failed for db:\S+ login:\S+ from <HOST>
`-
user@tempdev:/etc/fail2ban# cat /var/log/odoo/odoo.log | grep 'Login failed'
2020-12-11 12:54:06,442 1620 INFO TestSRV odoo.addons.base.models.res_users: Login failed for db:TestSRV login:asfd from 1.2.23.3
2020-12-11 13:11:20,945 1620 INFO TestSRV odoo.addons.base.models.res_users: Login failed for db:TestSRV login:asfd from 1.2.23.3
2020-12-11 13:12:07,928 1620 INFO TestSRV odoo.addons.base.models.res_users: Login failed for db:TestSRV login:asdf from 1.2.23.3
Solution 1:
Fail2ban surely cuts the part of string matched datepattern out, but a space still remains, so you have to add \s*
after the anchor before \d+
:
-failregex = ^\d+ INFO \S+ \S+ Login failed for db:\S+ login:\S+ from <HOST>
+failregex = ^\s*\d+ INFO \S+ \S+ Login failed for db:\S+ login:\S+ from <HOST>