summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2021-03-02 12:54:32 +0100
committerErich Eckner <git@eckner.net>2021-03-02 12:54:32 +0100
commitbcbd67c057e1e8e44384cf420e572ef59f646410 (patch)
treebf3b2ffd15b9cf11f284e9138dfc27223d0bc828
downloadjournal-watcher-bcbd67c057e1e8e44384cf420e572ef59f646410.tar.xz
initial commit: Skript seems to work
-rwxr-xr-xjournal-watcher.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/journal-watcher.py b/journal-watcher.py
new file mode 100755
index 0000000..91b9c34
--- /dev/null
+++ b/journal-watcher.py
@@ -0,0 +1,27 @@
+#!/bin/python
+
+from systemd import journal
+import re
+from time import sleep
+from email.mime.text import MIMEText
+from subprocess import Popen, PIPE
+
+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]+)')
+
+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())
+ item=j.get_next()
+ sleep(10)