fix: update banned metrics to exclude expired bans
Update the database query counting the number of banned IPs to filter out any bans that have already expired. An expired ban is defined as a ban where the "time of ban" plus the "duration of ban" is less than the current time. This is necessary because bans that have expired are not automatically removed from the database and will cause metrics to diverge from the counts reported by `fail2ban-client`.
This commit is contained in:
parent
a5e1ae4495
commit
526b1c7272
1 changed files with 1 additions and 1 deletions
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
const queryBadIpsPerJail = "SELECT j.name, (SELECT COUNT(1) FROM bips b WHERE j.name = b.jail) FROM jails j"
|
||||
const queryBannedIpsPerJail = "SELECT j.name, (SELECT COUNT(1) FROM bans b WHERE j.name = b.jail) FROM jails j"
|
||||
const queryBannedIpsPerJail = "SELECT j.name, (SELECT COUNT(1) FROM bans b WHERE j.name = b.jail AND b.timeofban + b.bantime >= strftime('%s','now') + 0) FROM jails j"
|
||||
const queryJailNameToEnabled = "SELECT j.name, j.enabled FROM jails j"
|
||||
|
||||
type Fail2BanDB struct {
|
||||
|
|
Loading…
Reference in a new issue