Open moritzj29 opened 3 years ago
replace the split(";") with split("m")
works for me. make sure the ";" isnt in the config file
I recommend to use the official method from fail2ban itself to translate the values/string to seconds (MyTime.str2seconds)
Hello, I just started to use this project. First of all, thanks for all the work put into this!
I realized that my bantime configs are not parsed correctly from the jail files, either resulting in a crash of the program or resulting in no bans exported to prometheus.
Case 1: strings
fail2ban allows to set the bantime as string, e.g.
1d
for 1 day. If I read the code correctly, currently this exporter requires the bantime to be set in seconds, as it is converted toint
: https://github.com/vdcloudcraft/fail2ban-geo-exporter/blob/aa0fa3fb033da3f71e9076a187ddf2ad5ad46830/fail2ban-exporter.py#L60 fail2ban uses the methodstr2seconds
inmytime.py
for conversion. I think it would be best to use the very same method here to avoid different behaviours. So fail2ban needs to be included in therequirements.txt
, right? A simple workaround is to specify all bantimes in seconds in the jail files.Case 2: permanent bans
I use fail2ban to ban some IPs forever, therefore I set the bantime to negative values. At least this causes no crash, since the value can be converted to integer. But those bans are not included in the metrics, since the selection from the database makes sense only for positive bantimes. If the bantime is negative, one could omit the
WHERE
clause completely in the database query.I'll will try to find some time to fiddle around with this and eventually create a PR. Feedback on these ideas is very much welcome!