A small, self-hosted monitor that sends alerts through Pushover. Pure Python standard library, no dependencies: one daemon, a SQLite file, and an admin TUI.
It does two kinds of check:
- Push (dead-man's switch). A cron job, worker or host pings the watchdog. You get an alert when a ping reports failure, when pings stop arriving, or when a job reports that it started but never finishes. This works for hosts behind firewalls, because the watchdog never has to reach them.
- Pull (probe). The watchdog checks the target itself on a schedule, by fetching a URL (for example a web server's index page, optionally checking for text on it) or by opening a TCP port.
Alerts are sent only when a check's state changes: one alert when it goes down, one when it recovers. You can optionally add a single "still down" reminder. Checks can be paused for maintenance, or you can mute all notifications at once while every check keeps running. If a Pushover send fails, the alert waits in an outbox and is retried.
watchdog · 4 checks · 1 down · 1 paused
NAME TYPE GROUP STATUS LAST SEEN TARGET / REASON
db-primary tcp ops up (paused) 8s ago localhost:9132
nightly-backup push ops up 35s ago ping every 24h
api-health http sites up 8s ago http://localhost:9132/health
www-home http sites down 8s ago HTTP 503 (expected 200-399)
a add Enter view e edit p pause r resume d delete / filter m mute all t test alert q quit
(The admin TUI, captured from a local test instance with four checks.)
Requirements
- Server: Linux with systemd, Python 3.9+ (with SQLite 3.24+), and a TLS reverse proxy (Apache or nginx) in front of it.
- Monitored hosts:
shandcurl.
Install (server)
git clone https://github.com/lucidbeaming/watchdog.git && cd watchdog
sudo deploy/install.sh
This creates a watchdog system user and installs:
- the code in
/opt/watchdogand thewatchdogcommand in/usr/local/bin; /etc/watchdog/watchdog.iniand/etc/watchdog/pushover.env(only if they don't already exist);- the systemd unit
watchdogd.service.
The SQLite database lives in /var/lib/watchdog.
Then:
- Put your Pushover application token and user key in
/etc/watchdog/pushover.env. Keys are case-insensitive:pushover_token=... pushover_user=... - Set
public_urlin/etc/watchdog/watchdog.ini. - Add the reverse proxy to your TLS virtual host (see Reverse proxy).
- Check that alerts reach your phone:
sudo watchdog test-alert. - Start the daemon:
sudo systemctl enable --now watchdogd. - Add checks:
sudo watchdog tui.
To upgrade, pull the new code, re-run sudo deploy/install.sh, then run
sudo systemctl restart watchdogd. Existing config and data are kept.
Uninstall
To remove the server, or to clean up a client where the full server was installed by
mistake (without --client), run:
sudo systemctl disable --now watchdogd
sudo rm -f /etc/systemd/system/watchdogd.service && sudo systemctl daemon-reload
sudo rm -rf /opt/watchdog /var/lib/watchdog /usr/local/bin/watchdog
sudo rm -f /etc/watchdog/watchdog.ini
sudo userdel watchdog
/var/lib/watchdogholds the database, so this deletes all checks and their history.- The client tools in
/usr/local/bin/wd-*stay. /etc/watchdog/pushover.envstays too, in casewd-watch-watchdogon this host needs it. If it still contains theREPLACE_WITH_…placeholders, delete it.- After
userdel, reset the directory's ownership withsudo chown root:root /etc/watchdog && sudo chmod 700 /etc/watchdog.
Reverse proxy
The daemon listens on 127.0.0.1:8787 only. Publish it through the web server that
already serves your domain over TLS, so ping URLs look like
https://watchdog.example.com/watchdog/ping/<token>. Don't open port 8787 in the
firewall: the proxy reaches it over loopback, and inbound traffic arrives on 443 as usual.
Apache. Enable the proxy modules:
sudo a2enmod proxy proxy_http
Add these lines inside your existing <VirtualHost *:443> block (also in
deploy/apache-snippet.conf):
ProxyPass /watchdog/ http://127.0.0.1:8787/
ProxyPassReverse /watchdog/ http://127.0.0.1:8787/
Then check the config and reload:
sudo apachectl configtest && sudo systemctl reload apache2
nginx. Add this inside your existing TLS server { } block (also in
deploy/nginx-snippet.conf):
location /watchdog/ {
proxy_pass http://127.0.0.1:8787/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 64k;
}
Then check the config and reload:
sudo nginx -t && sudo systemctl reload nginx
Check that it works:
curl https://watchdog.example.com/watchdog/healthz
This returns ok once the daemon is running. A ping with an unknown token returns 404
with the plain-text body not found. That body comes from the daemon. A styled HTML
error page instead means the request stopped at the proxy, so the proxy rule isn't
matching:
curl -sS -w ' [HTTP %{http_code}]\n' https://watchdog.example.com/watchdog/ping/00000000000000000000000000000000
Ping URLs contain each check's token, and web servers log full URLs. To keep pings out
of Apache's access log, replace the vhost's CustomLog line with:
SetEnvIf Request_URI "^/watchdog/" nolog
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!nolog
For nginx, add access_log off; to the location /watchdog/ block.
If you use a different path than /watchdog/, change it in both the proxy config and
public_url in watchdog.ini. Keep the trailing slashes, so the proxy strips the prefix
before the request reaches the daemon.
Admin TUI
sudo watchdog tui opens the list of checks, which refreshes every 2 seconds.
| Key | Action |
|---|---|
a |
add a check |
Enter |
details, ping URL and recent events |
e |
edit |
p / r |
pause for a duration (30m, 2h, 1d) / resume |
d |
delete (asks for confirmation) |
/ |
filter by name, group, label or type |
m |
mute all notifications for a duration, or until unmuted (leave the duration empty); press again to unmute |
t |
send a test notification |
n |
(in details) replace a push check's token |
q |
quit |
In the add/edit form:
↑/↓orTabmove between fields.←/→orSpacechange a choice.F2orCtrl-Ssaves;Esccancels.
The fields shown depend on the type. Saving a push check generates its secret ping URL, which you can select and copy from the details screen.
While notifications are muted, checks keep running and their status keeps updating,
and the TUI header says so. When you unmute, any check that is still down alerts once.
A check that went down and recovered during the mute sends nothing. Alerts are muted only
inside the watchdog: wd-watch-watchdog on another host still alerts if the watchdog
itself stops responding.
Changes take effect on the daemon's next tick (15 seconds by default), with no restart.
Run as root, the watchdog command switches to the watchdog user so the database
stays owned by the service.
Check types and fields
| Type | What it watches | Key fields |
|---|---|---|
push |
pings arrive every interval | interval, grace |
http |
GET URL returns an expected status |
URL, expect status (200-399, 200,301), expect text, timeout |
tcp |
a connection to host:port succeeds | host, port, timeout |
All check types also have:
- label: shown in alerts;
- group: for filtering and pausing together;
- Pushover priority:
-2to2. Priority2repeats until acknowledged; - sound and device;
- remind after;
- enabled.
For http and tcp checks, failures before alert sets how many probes must fail in
a row before the check counts as down.
A push check goes down when:
- the last ping was a failure (
/fail, or a nonzero exit code); - no ping has arrived for interval + grace;
- a
/startping has no matching/okor/failwithin grace (or within interval, if grace is 0).
Ping API
Monitored hosts call these through the proxy, at https://<your-domain>/watchdog/....
Both GET and POST work. A POST body (the last 2 KB is kept) becomes the event
message and appears in the alert.
| Path | Meaning |
|---|---|
/ping/<token> or /ping/<token>/ok |
success |
/ping/<token>/fail |
failure |
/ping/<token>/start |
job started |
/ping/<token>/<exit-code> |
0 is success, anything else is failure |
/healthz |
200 if the scheduler is running, otherwise 503 |
An unknown token returns 404.
Each ping records the address it came from. Behind the reverse proxy, that's the last
X-Forwarded-For entry, which the proxy itself appends, so a client can't fake it. The
header is trusted only on requests that arrive from localhost. The details screen in the
TUI and watchdog show list the source of every event. For a push check, the "from"
line warns when recent pings came from more than one address, which usually means two
hosts were set up with the same ping URL.
Client tools (monitored hosts)
Install them with sudo deploy/install.sh --client, or copy the files in client/ to
/usr/local/bin.
wd-ping <url> [ok|fail|start|<code>] [message|-]sends one ping. A message of-reads it from stdin. It prints nothing when the ping is accepted. When the ping fails, it prints the reason on stderr, without the token:token not recognized (HTTP 404),could not connect to …, or another HTTP status. It still exits 0, so monitoring never breaks a job; setWD_STRICT=1to exit 1 instead.wd-run <url> -- <command...>wraps any job. It sendsstart, runs the command, then sends the exit code with the last 20 lines of output. The output is still printed for cron mail, and the exit code is passed through.wd-probes.shis sourced by host self-check scripts. It providesprobe_systemd,probe_tcp,probe_http,probe_disk,probe_mem,probe_processandprobe_cmd.wd_report <url>then sendsok, orfailwith one line per problem. Seeexamples/host-self-check.sh.wd-watch-watchdog <healthz-url> [env-file]runs from cron on a different host. It sends Pushover alerts directly when the watchdog itself stops responding, and again when it recovers.
See examples/crontab.example for typical cron lines.
Adding a host
- Create a push check. In
watchdog tui, add one with the interval set to the cron schedule (e.g.300for every 5 minutes). Pause it (p) until the host is ready, so it doesn't alert as "never pinged" while you set things up. - Copy the check's ping URL. It's on the details screen, or run
watchdog show <name>. Each host needs its own check and URL. - Install the client tools on the host:
git clone https://github.com/lucidbeaming/watchdog.git && sudo watchdog/deploy/install.sh --client. Always use--clienton monitored hosts; without it, the install sets up a second watchdog server. - Write a self-check script for the host, e.g.
/usr/local/sbin/<host>-self-check, starting fromexamples/host-self-check.sh. Then runsudo chmod 755 /usr/local/sbin/<host>-self-check. - Test it as described in Testing a cron job.
- Add the cron line in
/etc/cron.d/watchdog, then resume the check (r).
Don't copy a cron file from one host to another without changing both the script name and the ping URL. The copy would run a script that doesn't exist there, or ping another host's check.
Self-check tips
- Prefer probes that don't need root.
probe_systemd,probe_tcp,probe_http,probe_diskandprobe_memall work as a normal user. Admin tools that need root (for examplemysqladminwith admin credentials) mean running that host's cron line asroot. Often a port check (probe_tcp 127.0.0.1 3306) is enough. - Find what to watch:
systemctl list-units --type=service --state=runninglists the services on a host.
Watching the watchdog
wd-watch-watchdog alerts you if the watchdog server itself goes down. Run it on one
host other than the server. It needs that host's own copy of the Pushover keys:
sudo install -d -m 700 /etc/watchdog
sudo install -m 600 /dev/null /etc/watchdog/pushover.env # then add pushover_token / pushover_user
Then add this cron line in /etc/cron.d/watchdog. It runs as root because it reads the
root-only key file:
*/5 * * * * root wd-watch-watchdog https://watchdog.example.com/watchdog/healthz
Test it once with
sudo wd-watch-watchdog https://watchdog.example.com/watchdog/healthz && echo ok.
Updating client hosts
Updating needs only the client tools. A small script on each host keeps it to one step:
#!/usr/bin/env bash
# ~/deploywatchdog.sh: update the checkout and reinstall the client tools.
set -euo pipefail
cd "$HOME/watchdog"
git pull --ff-only
sudo deploy/install.sh --client
Run it as your normal user, not with sudo. Self-check scripts and cron files are left
alone.
Testing a cron job
A job that works when you run it by hand can still fail under cron. Cron runs the
command as the user in the cron line, with an almost empty environment, and it runs the
script directly rather than through sh. With >/dev/null 2>&1 on the line, the error
also disappears. Before relying on a new job, check these four things.
1. The token belongs to the right check. Compare the URL in the cron line with
sudo watchdog show <check> on the watchdog server. A token copied from the wrong
check pings that other check instead. The details screen in the TUI flags this: a "from"
line with several addresses means more than one host is using the same URL.
2. The script is executable. ls -l /usr/local/sbin/<script> must show x
permissions (-rwxr-xr-x). Running it as sh script works without them, but cron needs
them. Fix with sudo chmod 755 /usr/local/sbin/<script>.
3. It works the way cron runs it. Run the exact command from the cron line, as the
same user and in an empty environment, with WD_STRICT=1 so a failed ping shows up in
the exit code:
sudo -u USER env -i HOME=/tmp SHELL=/bin/sh \
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
sh -c 'WD_STRICT=1 host-self-check https://watchdog.example.com/watchdog/ping/TOKEN; echo "exit $?"'
exit 0 with no wd-ping: message means the ping was accepted, and the check's "last
seen" in the TUI resets.
4. Cron runs it. After the next scheduled time, look for a CMD line:
sudo grep CRON /var/log/syslog | tail -5
If no CMD line appears:
- Files in
/etc/cron.dmust be owned by root and not writable by group or others. - Every line needs a user column after the five schedule fields.
- The file must end with a newline: cron ignores a last line without one.
- Lines in
crontab -ehave no user column. - If it's still missing after you fix the file, restart cron with
sudo systemctl restart cron(or reboot) so it rereads/etc/cron.d.
If CMD lines appear but the check never updates, go back to steps 1–3.
Command line
watchdog serve run the daemon (used by systemd)
watchdog tui admin TUI
watchdog status [--group G] table of checks; exits 1 if any is down
watchdog show NAME details, ping URL, recent events
watchdog pause NAME|group:G 2h
watchdog resume NAME|group:G
watchdog mute [DURATION] stop all notifications; checks keep running
watchdog unmute
watchdog test-alert [MESSAGE]
watchdog new-token
watchdog init-db
The config file is found from, in order: -c FILE, $WATCHDOG_CONFIG,
./watchdog.ini, then /etc/watchdog/watchdog.ini.
See deploy/watchdog.example.ini for every setting.
Development
cp deploy/watchdog.example.ini watchdog.ini # gitignored
# set: listen = 127.0.0.1:8787, public_url = http://127.0.0.1:8787,
# [database] path = watchdog.db, [pushover] env_file = .env
bin/watchdog serve # in one terminal
bin/watchdog tui # in another
python3 -m unittest discover -s tests -t .
The tests cover:
- engine logic, against a fake clock;
- the HTTP API;
- the Pushover client, against a stub server;
- the shell clients, against a real daemon;
- the TUI, through a pseudo-terminal.
.env, *.ini, databases and local/ are gitignored. Keep real hostnames and tokens
out of tracked files.
Related projects
- claudeproxy: another small self-hosted service, a local Anthropic ↔ OpenAI API proxy
License
MIT. See LICENSE.