aboutsummaryrefslogtreecommitdiffstats
path: root/python/onfailure.py
blob: 17bb867b22deb5f189df839a776c4a3762661407 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from systemd import journal
import os
import argparse
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"),
    )