commit
1c6714c31c
@ -1,102 +0,0 @@
|
||||
From 2009f1c4346597dcc4fd27151d220ea4a7806fdd Mon Sep 17 00:00:00 2001
|
||||
From: sebres <serg.brester@sebres.de>
|
||||
Date: Tue, 10 Jan 2017 10:59:53 +0100
|
||||
Subject: [PATCH] fail2ban-regex: fix for systemd-journal (see gh-1657)
|
||||
|
||||
---
|
||||
fail2ban/client/fail2banregex.py | 31 ++++++++++++++-----------------
|
||||
fail2ban/server/filtersystemd.py | 8 ++++++++
|
||||
2 files changed, 22 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/fail2ban/client/fail2banregex.py b/fail2ban/client/fail2banregex.py
|
||||
index 71f5095..13fa35d 100755
|
||||
--- a/fail2ban/client/fail2banregex.py
|
||||
+++ b/fail2ban/client/fail2banregex.py
|
||||
@@ -43,12 +43,12 @@
|
||||
from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError
|
||||
|
||||
try:
|
||||
- from systemd import journal
|
||||
from ..server.filtersystemd import FilterSystemd
|
||||
except ImportError:
|
||||
- journal = None
|
||||
+ FilterSystemd = None
|
||||
|
||||
from ..version import version
|
||||
+from .jailreader import JailReader
|
||||
from .filterreader import FilterReader
|
||||
from ..server.filter import Filter, FileContainer
|
||||
from ..server.failregex import RegexException
|
||||
@@ -82,7 +82,7 @@ def pprint_list(l, header=None):
|
||||
s = ''
|
||||
output( s + "| " + "\n| ".join(l) + '\n`-' )
|
||||
|
||||
-def journal_lines_gen(myjournal):
|
||||
+def journal_lines_gen(flt, myjournal): # pragma: no cover
|
||||
while True:
|
||||
try:
|
||||
entry = myjournal.get_next()
|
||||
@@ -90,7 +90,7 @@ def journal_lines_gen(myjournal):
|
||||
continue
|
||||
if not entry:
|
||||
break
|
||||
- yield FilterSystemd.formatJournalEntry(entry)
|
||||
+ yield flt.formatJournalEntry(entry)
|
||||
|
||||
def get_opt_parser():
|
||||
# use module docstring for help output
|
||||
@@ -513,25 +513,22 @@ def start(self, opts, args):
|
||||
except IOError as e:
|
||||
output( e )
|
||||
return False
|
||||
- elif cmd_log == "systemd-journal": # pragma: no cover
|
||||
- if not journal:
|
||||
+ elif cmd_log.startswith("systemd-journal"): # pragma: no cover
|
||||
+ if not FilterSystemd:
|
||||
output( "Error: systemd library not found. Exiting..." )
|
||||
return False
|
||||
- myjournal = journal.Reader(converters={'__CURSOR': lambda x: x})
|
||||
+ output( "Use systemd journal" )
|
||||
+ output( "Use encoding : %s" % self.encoding )
|
||||
+ backend, beArgs = JailReader.extractOptions(cmd_log)
|
||||
+ flt = FilterSystemd(None, **beArgs)
|
||||
+ flt.setLogEncoding(self.encoding)
|
||||
+ myjournal = flt.getJournalReader()
|
||||
journalmatch = self._journalmatch
|
||||
self.setDatePattern(None)
|
||||
if journalmatch:
|
||||
- try:
|
||||
- for element in journalmatch:
|
||||
- if element == "+":
|
||||
- myjournal.add_disjunction()
|
||||
- else:
|
||||
- myjournal.add_match(element)
|
||||
- except ValueError:
|
||||
- output( "Error: Invalid journalmatch: %s" % shortstr(" ".join(journalmatch)) )
|
||||
- return False
|
||||
+ flt.addJournalMatch(journalmatch)
|
||||
output( "Use journal match : %s" % " ".join(journalmatch) )
|
||||
- test_lines = journal_lines_gen(myjournal)
|
||||
+ test_lines = journal_lines_gen(flt, myjournal)
|
||||
else:
|
||||
output( "Use single line : %s" % shortstr(cmd_log) )
|
||||
test_lines = [ cmd_log ]
|
||||
diff --git a/fail2ban/server/filtersystemd.py b/fail2ban/server/filtersystemd.py
|
||||
index 3023155..908112a 100644
|
||||
--- a/fail2ban/server/filtersystemd.py
|
||||
+++ b/fail2ban/server/filtersystemd.py
|
||||
@@ -175,6 +175,14 @@ def uni_decode(self, x):
|
||||
return v
|
||||
|
||||
##
|
||||
+ # Get journal reader
|
||||
+ #
|
||||
+ # @return journal reader
|
||||
+
|
||||
+ def getJournalReader(self):
|
||||
+ return self.__journal
|
||||
+
|
||||
+ ##
|
||||
# Format journal log entry into syslog style
|
||||
#
|
||||
# @param entry systemd journal entry dict
|
@ -1 +1 @@
|
||||
SHA512 (fail2ban-0.9.6.tar.gz) = 4a0c09451409f81882664c2316867aa1c45572018b7f4647f8dc356f9115c9c2ff4a17098ef249bcc6712acfed6b5c99518b1c069ef1bf253d96c900d29be1d2
|
||||
SHA512 (fail2ban-0.9.7.tar.gz) = 2c28f892e882f1c7d9bc33d16e1f469f65aa198a1dd9fe409367cd857006d7b7e6e4c88f1075f726f8b3e268da5a422d9fae0ebe12457016d814e2b8eea2465a
|
||||
|
Loading…
Reference in new issue