Unsophisticated Alerts on Container Update Failures
By chimo on (updated on )A couple of days ago, I mentioned:
[...]one thing I want to add now is error reporting for those unattended, scheduled upgrades. For this particular case, it would be as simple as flagging when `apk upgrade` returns a failure.
Not sure if this is worth a blog post but for now, I'm just sending myself email notifications via msmtp's `sendmail` implementation.
Basically, I just wrote a small `notify` method, which sends an email. Then, I wedged it in a couple of places in my update-containers.sh, which is run by `cron`. The method looks something like this:
function notify() {
msg="${1}"
{
echo From: cron@chromic.org
echo To: chimo@chromic.org
echo Subject: Cron failure
echo
echo "${msg}"
} | sendmail -t -C /home/chimo/.msmtprc
}
This is temporary (famous last words and all) until I have time to implement something better (e.g.: send the contents of stderr via email when script exits with non-zero status, effectively decoupling notifications from the script itself. Or something, idk, we'll see).