// free agents / heartbeat-watchdog
💓 Heartbeat watchdog (dead man's switch)
“Warn me on Discord when my nightly backup, cron job or n8n workflow silently stops running.”
Free, no sign-up. MIT licence. Python standard library only, so there's nothing to pip install.
What it does
A self-hosted dead man's switch. Your jobs check in when they finish (touch a file, call a ping URL, or just succeed in n8n), and the watchdog alerts Discord or email once when a check-in is late and once when it's back. It catches what error alerts can't: a job that never ran because it was deactivated, the server rebooted, or cron stopped. It also catches runs that succeed but produce nothing: a backup file that is fresh but empty, or a job that checks in with ?count=0. It also does simple uptime checks on URLs.
What you need
- Python 3.9+ (no extra packages) or n8n
- A Discord webhook (or an email account that can send over SMTP)
- Optional: an n8n API key, to watch n8n workflows' last successful run
5-minute setup
Python
- Install Python 3.9+ and unzip the download.
- Try it with no accounts:
python3 heartbeat_watchdog.py --dry-run - Copy
.env.exampleto.envand fill it in. - Run:
set -a; . ./.env; set +a; python3 heartbeat_watchdog.py(Windows steps in the README).
n8n (no code)
- Workflows, then Import from file, then
heartbeat-watchdog.n8n.json. - Follow the yellow “Read me” note (credentials or webhook).
- Test workflow, then switch it to Active.
Run it on a schedule
Every 10 minutes (and, for ping heartbeats, keep `python3 heartbeat_watchdog.py serve` running as a service) with cron:
*/10 * * * * cd /path/to/heartbeat-watchdog && set -a && . ./.env && set +a && python3 heartbeat_watchdog.py >> run.log 2>&1On Windows use Task Scheduler. With n8n, the Schedule node does it for you.
Settings
| Variable | What it does |
|---|---|
CHECKS_FILE | Your heartbeats, default checks.json (copy checks.example.json): file, ping, n8n or url, each with a max_age like 15m, 2h, 26h. Optional: min_size for files ("1MB"; the target can be a pattern like /backups/*.sql.gz, newest file counts) and min_count for pings (jobs call /ping/name?count=12, or /ping/name/fail for a failed run) |
DISCORD_WEBHOOK_URL | Where alerts go |
EMAIL_TO / SMTP_HOST / SMTP_PORT / SMTP_USER / SMTP_PASSWORD | Optional: alerts by email |
N8N_URL / N8N_API_KEY | Optional: for n8n heartbeats, e.g. http://localhost:5678 |
PORT / PING_TOKEN | serve mode: ping receiver port (default 8765) and an optional secret ?token= |
What we tested
- Python, against mock Discord and n8n API servers: missing heartbeats of all four types alerted once in one message, nothing repeated while still down, one recovery message when they came back, and a second outage alerted again.
- Ping receiver: rejects a missing or wrong PING_TOKEN (403) and bad names (404), records good pings.
- 18 Oct 2026: added checks for runs that succeed but produce nothing. Tested with a mock Discord webhook: a fresh 0-byte backup next to an old 2 MB one alerted (min_size 1MB, pattern db-*.sql.gz), a ping with ?count=0 alerted (min_count 1), both in one message and not repeated; a 3 MB backup and ?count=12 sent one recovery message; /ping/name/fail alerted again; ?count=abc is refused (400); pings.json files from the earlier version still work.
- File age, n8n last successful execution (status=success, limit 1) and URL 2xx checks all tested; Discord HTTP 429 is retried; @everyone pings are disabled; --dry-run sends and saves nothing.
- n8n workflow run as an active workflow in a real n8n 2.43 install (check every minute for the test): two jobs pinged the webhook, the one with a 1-minute limit was alerted once to a mock Discord webhook, not repeated on the next check, reported back after a new ping, and alerted again when it went quiet; the job with a 60-minute limit never alerted.
Honest limits
- A watchdog on the same server dies with it. Run it on a second machine (a Raspberry Pi or a free cloud VM) or pair it with Healthchecks.io if the whole box going down matters.
- The ping receiver has no HTTPS of its own: keep it on your LAN/VPN or behind your reverse proxy, and set PING_TOKEN.
- Tested with mock Discord and n8n API servers, not a real Discord server.
- The n8n version can't warn you when n8n itself is down; use the Python version for that.
- min_size, min_count and /fail are in the Python version; the n8n workflow only checks that a ping arrived in time.
Related guides
Want one built for your task?
Describe it in one sentence. We build it, test it and email it to you, usually within 24h. Free while we're in beta.