Last active
June 27, 2016 21:12
-
-
Save vilhelmen/28927e6aa2260cd94d015fc2fa19dfb0 to your computer and use it in GitHub Desktop.
Email alert service for systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
LOG_DATA=$(mktemp --suffix='.log') | |
journalctl -o short --since -30min -u ${2} > ${LOG_DATA} | |
echo "Service ${2} has failed on ${1}. Log attached." | mutt -F mutt.cfg -s "${1} SERVICE FAILURE ALERT" -a ${LOG_LOC} $(cat recipients.cfg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Email alert service | |
# trigger with OnFailure=email-alert@%n.service | |
Requires=network-online.target | |
AssertFileNotEmpty=/opt/email-alert/mutt.cfg | |
AssertFileNotEmpty=/opt/email-alert/recipients.cfg | |
User=root | |
[Service] | |
Type=oneshot | |
PrivateTmp=true | |
PrivateDevices=true | |
ProtectSystem=full | |
ProtectHome=true | |
NoNewPrivileges=true | |
WorkingDirectory=/opt/email-alert/ | |
ExecStart=/opt/email-alert/email-alert.sh %H %I | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment