mirror of https://github.com/fail2ban/fail2ban
BF: Allow journal matches with spaces and "+" in
parent
c1226afe92
commit
09199095b4
|
@ -23,7 +23,7 @@ __author__ = "Cyril Jaquier, Lee Clemens, Yaroslav Halchenko, Steven Hiscocks"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2011-2012 Lee Clemens, 2012 Yaroslav Halchenko, 2013 Steven Hiscocks"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2011-2012 Lee Clemens, 2012 Yaroslav Halchenko, 2013 Steven Hiscocks"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
import logging, datetime
|
import logging, datetime, shlex
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
from systemd import journal
|
from systemd import journal
|
||||||
|
@ -68,18 +68,22 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
|
||||||
def addJournalMatch(self, match):
|
def addJournalMatch(self, match):
|
||||||
if self.__matches:
|
if self.__matches:
|
||||||
self.__journal.add_disjunction() # Add OR
|
self.__journal.add_disjunction() # Add OR
|
||||||
|
newMatches = [[]]
|
||||||
try:
|
try:
|
||||||
for match_element in match.split():
|
for match_element in shlex.split(match):
|
||||||
if match_element == "+":
|
if match_element == "+":
|
||||||
self.__journal.add_disjunction()
|
self.__journal.add_disjunction()
|
||||||
|
newMatches.append([])
|
||||||
else:
|
else:
|
||||||
self.__journal.add_match(match_element)
|
self.__journal.add_match(match_element)
|
||||||
except:
|
newMatches[-1].append(match_element)
|
||||||
|
except ValueError:
|
||||||
logSys.error("Error adding journal match for: %s", match)
|
logSys.error("Error adding journal match for: %s", match)
|
||||||
self.resetJournalMatches()
|
self.resetJournalMatches()
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
for match_element in match.split('+'):
|
self.__matches.extend(
|
||||||
self.__matches.append(match_element.strip())
|
" ".join(newMatch) for newMatch in newMatches)
|
||||||
logSys.debug("Adding journal match for: %s", match)
|
logSys.debug("Adding journal match for: %s", match)
|
||||||
##
|
##
|
||||||
# Reset a journal match filter called on removal or failure
|
# Reset a journal match filter called on removal or failure
|
||||||
|
@ -100,9 +104,12 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
|
||||||
# @param match journalctl syntax matches
|
# @param match journalctl syntax matches
|
||||||
|
|
||||||
def delJournalMatch(self, match):
|
def delJournalMatch(self, match):
|
||||||
|
match = " ".join(shlex.split(match))
|
||||||
if match in self.__matches:
|
if match in self.__matches:
|
||||||
del self.__matches[self.__matches.index(match)]
|
del self.__matches[self.__matches.index(match)]
|
||||||
self.resetJournalMatches()
|
self.resetJournalMatches()
|
||||||
|
else:
|
||||||
|
raise ValueError("Match not found")
|
||||||
|
|
||||||
##
|
##
|
||||||
# Get current journal match filter
|
# Get current journal match filter
|
||||||
|
|
Loading…
Reference in New Issue