from systemd import journal import os import sys if os.environ["EXIT_STATUS"] != "0": from serenitas.utils.exchange import ExchangeMessage service = sys.argv[1] em = ExchangeMessage() content = [] j = journal.Reader() j.add_match(_SYSTEMD_INVOCATION_ID=os.environ["INVOCATION_ID"]) for entry in j: content.append(entry["MESSAGE"]) em.send_email( f"{service} failed", "\n".join(content), ("fyu@lmcg.com", "ghorel@lmcg.com"), save_copy=False, )