From 93f5a9aaad9df08799995660c4eee356c50abc0b Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Sun, 14 Jul 2024 16:07:11 +0200 Subject: [PATCH] add timestamp to mailed journal log. Also restrict to 200 rows to prevent unreasonable large emails... --- src/sysalert/email.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sysalert/email.py b/src/sysalert/email.py index 2790670..d9163a6 100644 --- a/src/sysalert/email.py +++ b/src/sysalert/email.py @@ -50,7 +50,11 @@ def failure(name, failures, config): reader.add_match(MONITOR_INVOCATION_ID=latest_inv_id) reader.add_disjunction() reader.add_match(_SYSTEMD_INVOCATION_ID=latest_inv_id) - journal_txt = "\n".join([entry['MESSAGE'] for entry in reader]) + journal_txt = "\n".join( + [ + f'{entry["_SOURCE_REALTIME_TIMESTAMP"]}: {entry["MESSAGE"]}' + for entry in list(reader)[-200:] + ]) if nr_failures <= 1: subject=f"{hostname} - {name}: failure"