remove systemctl status output from email.

I can't seem to find a way to allow systemctl status in combination with
DynamicUser= for the sysalert service...
This commit is contained in:
Fredrik Eriksson 2024-07-13 20:55:45 +02:00
parent aa1c2d0781
commit 0aae142c05
Signed by: feffe
GPG Key ID: E6B5580B853D322B

View File

@ -1,20 +1,9 @@
import email import email
import smtplib import smtplib
import socket import socket
import subprocess
import systemd.journal import systemd.journal
def _get_status(name):
cmd = ['/usr/bin/systemctl', 'status', name]
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE)
out, err = proc.communicate()
out = out.decode('utf-8')
return out
def _send_email(subject, message, config): def _send_email(subject, message, config):
mail = email.message.EmailMessage() mail = email.message.EmailMessage()
hostname = socket.getfqdn() hostname = socket.getfqdn()
@ -44,9 +33,6 @@ def success(name, failures, config):
subject=f'{hostname} - {name}: recovery' subject=f'{hostname} - {name}: recovery'
message=f""" message=f"""
{name} has recovered after {nr_failures} failures. {name} has recovered after {nr_failures} failures.
Current status:
{cur_status}
""" """
_send_email(subject, message, config) _send_email(subject, message, config)
@ -72,11 +58,6 @@ def failure(name, failures, config):
subject=f"{hostname} - {name}: failure" subject=f"{hostname} - {name}: failure"
message=f""" message=f"""
New failure for {name}. New failure for {name}.
Current status:
{cur_status}
Latest journal log: Latest journal log:
{journal_txt} {journal_txt}
@ -85,11 +66,6 @@ Latest journal log:
subject=f"{hostname} - {name}: {nr_failures} failures" subject=f"{hostname} - {name}: {nr_failures} failures"
message=f""" message=f"""
{nr_failures} failures for {name} ({prev_failures} since last notification). {nr_failures} failures for {name} ({prev_failures} since last notification).
Current status:
{cur_status}
Latest journal log: Latest journal log:
{journal_txt} {journal_txt}