commit 9c29b9222d81fb8b5ec84853bd8b0888bca23254 Author: Micha vor dem Berge m@mcvdb.de Date: Wed Jan 27 13:42:22 2010 +0000
Added support for ssmtp to mail_mod and changed module priorities in config files.
Signed-off-by: Konstantin Ryabitsev mricon@kernel.org
etc/modules.d/mail.conf.in | 5 +++-- etc/modules.d/notices.conf.in | 2 +- etc/modules.d/spamd.conf.in | 2 +- modules/mail_mod.py | 37 ++++++++++++++++++++++++++++++++----- 4 files changed, 37 insertions(+), 9 deletions(-) --- diff --git a/etc/modules.d/mail.conf.in b/etc/modules.d/mail.conf.in index 04e107e..fc98745 100644 --- a/etc/modules.d/mail.conf.in +++ b/etc/modules.d/mail.conf.in @@ -5,15 +5,16 @@ files = /var/log/maillog[.#] enabled = yes internal = yes outhtml = yes -priority = 5 +priority = 3
[conf] ## -# Enable sendmail, postfix, or both +# Enable sendmail, postfix, qmail, ssmtp or all of them # enable_sendmail = 1 enable_postfix = 1 enable_qmail = 0 +enable_ssmtp = 0 ## # Report at most this many "top things" # diff --git a/etc/modules.d/notices.conf.in b/etc/modules.d/notices.conf.in index 3043156..93fccd3 100644 --- a/etc/modules.d/notices.conf.in +++ b/etc/modules.d/notices.conf.in @@ -5,7 +5,7 @@ files = /var/log/messages[.#], /var/log/secure[.#], /var/log/maillog[.#] enabled = yes internal = yes outhtml = yes -priority = 7 +priority = 9
[conf] ## diff --git a/etc/modules.d/spamd.conf.in b/etc/modules.d/spamd.conf.in index 7ebd7f4..107d87a 100644 --- a/etc/modules.d/spamd.conf.in +++ b/etc/modules.d/spamd.conf.in @@ -5,7 +5,7 @@ files = /var/log/maillog[.#] enabled = no internal = yes outhtml = yes -priority = 7 +priority = 4
[conf] ## diff --git a/modules/mail_mod.py b/modules/mail_mod.py index 1dfd772..9af9552 100644 --- a/modules/mail_mod.py +++ b/modules/mail_mod.py @@ -1,6 +1,8 @@ #!/usr/bin/python -tt """ -Description will eventually go here. +This is an epylog module that looks for mail relevant outputs. +Output is a general mail report (overview) and the top x systems +and recipients. """ ## # Copyright (C) 2003 by Duke University @@ -44,7 +46,7 @@ class mail_mod(InternalModule): rc = re.compile postfix_map = { rc('postfix/smtpd[\d+]:\s\S*:'): self.postfix_smtpd, - rc('postfix/n*qmgr[\d+]:\s\S*:'): self.postfix_qmgr, + rc('postfix/.*qmgr[\d+]:\s\S*:'): self.postfix_qmgr, rc('postfix/local[\d+]:\s\S*:'): self.postfix_local, rc('postfix/smtp[\d+]:\s\S*:\sto='): self.postfix_smtp } @@ -59,21 +61,27 @@ class mail_mod(InternalModule): rc('qmail:\s\d+.\d+\sdelivery'): self.qmail_delivery, rc('qmail:\s\d+.\d+\sbounce\smsg\s\d+'): self.qmail_bounce } + + ssmtp_map = { + rc('sSMTP[\d+]:\sSent\smail'): self.ssmtp_sent + }
do_postfix = int(opts.get('enable_postfix', '0')) do_sendmail = int(opts.get('enable_sendmail', '1')) do_qmail = int(opts.get('enable_qmail', '0')) + do_ssmtp = int(opts.get('enable_ssmtp', '1'))
self.regex_map = {} if do_postfix: self.regex_map.update(postfix_map) if do_sendmail: self.regex_map.update(sendmail_map) if do_qmail: self.regex_map.update(qmail_map) + if do_ssmtp: self.regex_map.update(ssmtp_map)
self.toplim = int(opts.get('top_report_limit', '5'))
self.postfix_ident_re = rc('[\d+]:\s*([A-Z0-9]*):') self.postfix_smtpd_re = rc('client=\S*[(\S*)]') - self.postfix_qmgr_re = rc('from=(\S*),.*size=(\d*)') + self.postfix_qmgr_re = rc('from=(\S*),.*size=(\d*),.*nrcpt=(\d*)') self.postfix_local_re = rc('to=(\S*),.*status=(\S*)\s((.*))') self.postfix_smtp_re = rc('to=(\S*),.*status=(\S*)')
@@ -90,6 +98,8 @@ class mail_mod(InternalModule): self.qmail_startdev_re = rc('to\s\S+\s(\S+)') self.qmail_delivery_re = rc('delivery\s\d+:\s(\S+):')
+ self.ssmtp_sent_re = rc('sSMTP[\d+]:\sSent\smail\sfor\s(\S+)\s((\d+).*)\suid=(\d+)\susername=(\S+)\soutbytes=(\d+)') + self.procmail_re = rc('/procmail')
self.bounce = 0 @@ -104,6 +114,7 @@ class mail_mod(InternalModule):
self.report_line = '<tr><td valign="top" align="right">%s</td><td valign="top" width="90%%">%s</td></tr>\n'
+ ## # Line-matching routines # @@ -123,8 +134,8 @@ class mail_mod(InternalModule): sys, msg, mult = self.get_smm(linemap) id = self._get_postfix_id(msg) self.logger.put(5, 'id=%s' % id) - try: sender, size = self.postfix_qmgr_re.search(msg).groups() - except: sender, size = (None, 0) + try: sender, size, recipients = self.postfix_qmgr_re.search(msg).groups() + except: sender, size, recipients = (None, 0, 0) size = int(size) self.logger.put(5, 'sender=%s, size=%d' % (sender, size)) restuple = self._mk_restuple(sys, id, sender=sender, size=size) @@ -235,6 +246,22 @@ class mail_mod(InternalModule): restuple = self._mk_restuple(sys, id, status=self.bounce) return {restuple: mult}
+ def ssmtp_sent(self, linemap): + sys, msg, mult = self.get_smm(linemap) + try: to, status, uid, user, size = self.ssmtp_sent_re.search(msg).groups() + except: + self.logger.put(3, 'Odd ssmtp_sent line: %s' % msg) + return None + size = int (size) + status = int (status) + self.logger.put(5, 'to=%s, status=%i, uid=%s, user=%s, size=%i' % (to, status, uid, user, size)) + if (status >= 100) and (status <= 199): status = self.warning + elif (status >= 200) and (status <= 299): status = self.success + elif (status >= 300) and (status <= 499): status = self.bounce + elif (status >= 500) and (status <= 599): status = self.warning + restuple = self._mk_restuple(sys, id, to=to, status=status, size=size) + return {restuple: mult} + ## # HElpers #