Get notification when systemd-monitored service enters failed state
Just my way to notify :
/etc/systemd/system/notify-email@.service
[Unit]
Description=Sent email
[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c '/usr/bin/systemctl status %i | /usr/bin/mailx -Ssendwait -s "[SYSTEMD_%i] Fail" your_admin@company.blablabla'
[Install]
WantedBy=multi-user.target
add to systemd, example for ntpd.service:
systemctl enable /etc/systemd/system/notify-email@ntpd.service
At others services add:
systemctl edit ntpd
[Unit]
OnFailure=notify-email@%i.service
Reload the configuration:
systemctl daemon-reload