summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2021-04-19 16:40:56 +0200
committerErich Eckner <git@eckner.net>2021-04-19 16:40:56 +0200
commitf418bf650c401e8c0cde0bd1c7e81e7eb1dbfe3b (patch)
tree14a163f3b5944b33d18afd213be910f013cdc130
parentb5454a57db6652153d462561218e9c2c578182f8 (diff)
downloadjournal-watcher-f418bf650c401e8c0cde0bd1c7e81e7eb1dbfe3b.tar.xz
journal-watcher.py: match on both messages
-rwxr-xr-xjournal-watcher.py23
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)