brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: append the exit status to a Healthchecks ping so failures alert at once

Healthcheck
~/tips/tip-healthchecks-ping-exit-status

/usr/bin/certbot renew

Reports a job's exit code to Healthchecks.io so a failed run alerts right away.

The classic cron monitoring line only pings when the job succeeded. If the job fails, nothing happens, and Healthchecks.io notices once the period and the grace time have both run out. That is a long wait for a broken backup.

#!/bin/sh
/usr/bin/certbot renew
curl -fsS -m 10 --retry 3 -o /dev/null https://hc-ping.com/your-uuid-here/$?

This is the example from the Healthchecks.io documentation, with the usual curl options added. $? holds the exit status of the last command, and appending it to the ping URL tells Healthchecks.io what happened. An exit status of 0 counts as success, any non-zero value from 1 to 255 counts as a failure, and the alert goes out immediately. The check does not have to run late first.

Because $? is overwritten by every command, the curl line has to come directly after the command you care about. Put an echo in between and you report the exit status of the echo.

If you can’t build a URL with a number in it, for example in a Python script, there is a second form: append /fail.

curl -fsS -m 10 --retry 3 -o /dev/null https://hc-ping.com/your-uuid-here/fail

The documentation shows it in a Python try/finally block that pings the normal URL on success and the /fail URL otherwise.

One caveat: a script that crashes badly, or a machine that is off, sends no ping at all. The normal period and grace time still catch that. The exit status ping is a faster signal on top, not a replacement for the schedule. This tip follows the documentation and was not run against a live account.

Further reading: Signaling failures, How to monitor cron jobs

Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid

More Healthcheck tips curl -m 10 --retry 5 "https://hc-ping.com/my-ping-key/srv01?create=1" All Healthcheck tips (2) All topics

Link