summaryrefslogtreecommitdiff
path: root/config/action.d
diff options
context:
space:
mode:
authorsebres <serg.brester@sebres.de>2019-03-01 12:36:07 +0100
committersebres <serg.brester@sebres.de>2019-03-01 12:36:07 +0100
commit324f0ed7cc9233c992313586d475cfa9fa52df47 (patch)
tree2adae7a8ae54ed78974bd8f19f74e736136cdc79 /config/action.d
parenta3b7a0525ab3e55863742910549308ffe33f1c75 (diff)
parent415818d8038f49c7db3172a6640c19fea9cd6e43 (diff)
downloadfail2ban-324f0ed7cc9233c992313586d475cfa9fa52df47.tar.gz
Merge branch '0.10' into 0.11
Diffstat (limited to 'config/action.d')
-rw-r--r--config/action.d/badips.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/config/action.d/badips.py b/config/action.d/badips.py
index 1ad711f4..e5de7555 100644
--- a/config/action.d/badips.py
+++ b/config/action.d/badips.py
@@ -32,7 +32,7 @@ else: # pragma: 3.x no cover
from urllib import urlencode
from fail2ban.server.actions import ActionBase
-from fail2ban.helpers import str2LogLevel
+from fail2ban.helpers import splitwords, str2LogLevel
@@ -75,6 +75,9 @@ class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable
loglevel : int/str, optional
Log level of the message when an IP is (un)banned.
Default `DEBUG`.
+ Can be also supplied as two-value list (comma- or space separated) to
+ provide level of the summary message when a group of IPs is (un)banned.
+ Example `DEBUG,INFO`.
agent : str, optional
User agent transmitted to server.
Default `Fail2Ban/ver.`
@@ -91,8 +94,8 @@ class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable
return Request(url, headers={'User-Agent': self.agent}, **argv)
def __init__(self, jail, name, category, score=3, age="24h", key=None,
- banaction=None, bancategory=None, bankey=None, updateperiod=900, loglevel='DEBUG', agent="Fail2Ban",
- timeout=TIMEOUT):
+ banaction=None, bancategory=None, bankey=None, updateperiod=900,
+ loglevel='DEBUG', agent="Fail2Ban", timeout=TIMEOUT):
super(BadIPsAction, self).__init__(jail, name)
self.timeout = timeout
@@ -104,7 +107,9 @@ class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable
self.banaction = banaction
self.bancategory = bancategory or category
self.bankey = bankey
- self.loglevel = str2LogLevel(loglevel)
+ loglevel = splitwords(loglevel)
+ self.sumloglevel = str2LogLevel(loglevel[-1])
+ self.loglevel = str2LogLevel(loglevel[0])
self.updateperiod = updateperiod
self._bannedips = set()
@@ -350,9 +355,13 @@ class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable
s = ips - self._bannedips
p = len(s)
self._banIPs(s)
- self._logSys.log(self.loglevel,
- "Updated IPs for jail '%s' (-%d/+%d). Update again in %i seconds",
- self._jail.name, m, p, self.updateperiod)
+ if m != 0 or p != 0:
+ self._logSys.log(self.sumloglevel,
+ "Updated IPs for jail '%s' (-%d/+%d)",
+ self._jail.name, m, p)
+ self._logSys.debug(
+ "Next update for jail '%' in %i seconds",
+ self._jail.name, self.updateperiod)
finally:
self._timer = threading.Timer(self.updateperiod, self.update)
self._timer.start()