From 9bdf290e13c78977b91ba5c38fb6b111586bafb5 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 26 Mar 2024 14:33:31 +0100 Subject: [PATCH] Adding connect statistics to lib/pp_admintools/handler/pflogparse.py --- lib/pp_admintools/handler/pflogparse.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/pp_admintools/handler/pflogparse.py b/lib/pp_admintools/handler/pflogparse.py index 6206b9a..4942b13 100644 --- a/lib/pp_admintools/handler/pflogparse.py +++ b/lib/pp_admintools/handler/pflogparse.py @@ -27,7 +27,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.3.1' +__version__ = '0.3.2' # ============================================================================= @@ -67,6 +67,7 @@ class PostfixLogfileParser(HandlingObject): """Initialize the PostfixLogfileParser object.""" self.chain = {} self.active_smtpd_pid = {} + self.connect = {} super(PostfixLogfileParser, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, @@ -90,14 +91,18 @@ class PostfixLogfileParser(HandlingObject): self.chain = {} self.active_smtpd_pid = {} + self.connect = {} # ------------------------------------------------------------------------- def parse(self, fh): """Parse the content of a given logfile and store the results in self.chain.""" LOG.debug(_('Start parsing postfix logfile ...')) - for line in fh.readlines(): - self.evaluate_logline(line) + try: + for line in fh.readlines(): + self.evaluate_logline(line) + finally: + self.active_smtpd_pid = {} # ------------------------------------------------------------------------- def evaluate_logline(self, line): @@ -158,6 +163,10 @@ class PostfixLogfileParser(HandlingObject): m_conn = self.re_connect.search(message) if m_conn: + who = m_conn['client'] + if who.lower() == 'unknown': + who = m_conn['addr'] + chain = PostfixLogchainInfo( client_host=m_conn['client'], client_addr=m_conn['addr'], @@ -168,6 +177,10 @@ class PostfixLogfileParser(HandlingObject): ) self.active_smtpd_pid[pid] = chain + if who not in self.connect: + self.connect[who] = 0 + self.connect[who] += 1 + if self.verbose > 3: msg = 'Creating Postfix log chain:\n' + pp(chain.as_dict()) LOG.debug(msg) -- 2.39.5