You've already forked prometheus-fail2ban-exporter
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:
@ -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 {
|
||||
|
Reference in New Issue
Block a user