diff options
-rwxr-xr-x | journal-watcher.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/journal-watcher.py b/journal-watcher.py index 6e2be60..df1227e 100755 --- a/journal-watcher.py +++ b/journal-watcher.py @@ -10,19 +10,22 @@ j = journal.Reader() j.this_boot() j.add_match(_SYSTEMD_UNIT='courier-esmtpd.service') -# regex = re.compile('.*msg="534 SIZE=Message too big\.",cmd: MAIL FROM:[^<]*<([^>]+)> SIZE=([0-9]+)') -regex = re.compile('.*,from=[^<]*<([^>]+)>: 523 Message length \(([0-9]+) bytes\) exceeds administrative limit.*') +regexes = { + re.compile('.*msg="534 SIZE=Message too big\.",cmd: MAIL FROM:[^<]*<([^>]+)> SIZE=([0-9]+)'), + re.compile('.*,from=[^<]*<([^>]+)>: 523 Message length \(([0-9]+) bytes\) exceeds administrative limit.*') +} while True: item=j.get_next() while item!={}: - match = regex.match(item['MESSAGE']) - if match: - msg = MIMEText("Hi,\n\n{} hat eine zu grosze Email ({}) geschickt ({}).".format(match.group(1),match.group(2),item['SYSLOG_TIMESTAMP'])) - msg["From"] = "journal-watcher@eckner.net" - msg["To"] = "logs@eckner.net" - msg["Subject"] = "zu grosze Email von {}".format(match.group(1)) - p = Popen(["/usr/sbin/sendmailadvanced", "-t"], stdin=PIPE) - p.communicate(msg.as_bytes()) + for regex in regexes: + match = regex.match(item['MESSAGE']) + if match: + msg = MIMEText("Hi,\n\n{} hat eine zu grosze Email ({}) geschickt ({}).".format(match.group(1),match.group(2),item['SYSLOG_TIMESTAMP'])) + msg["From"] = "journal-watcher@eckner.net" + msg["To"] = "logs@eckner.net" + msg["Subject"] = "zu grosze Email von {}".format(match.group(1)) + p = Popen(["/usr/sbin/sendmailadvanced", "-t"], stdin=PIPE) + p.communicate(msg.as_bytes()) item=j.get_next() sleep(10) |