You can easily add Kidoz Health Check monitoring to a shell script. All you have to do is make an HTTP request at an appropriate place in the script. curl and wget are two common command-line HTTP clients you can use.
# Sends an HTTP GET request with curl:
curl -m 10 --retry 5 https://health.kidoz.net/ping/your-uuid-here
# Silent version (no stdout/stderr output unless curl hits an error):
curl -fsS -m 10 --retry 5 -o /dev/null https://health.kidoz.net/ping/your-uuid-here
Here's what each curl parameter does:
You can append /fail
or /{exit-status}
to any ping URL and use the resulting URL
to actively signal a failure. The exit status should be a 0-255 integer.
Kidoz Health Check will interpret exit status 0 as success and all non-zero values as failures.
The following example runs /usr/bin/certbot renew
, and uses the $?
variable to
look up its exit status:
#!/bin/sh
# Payload here:
/usr/bin/certbot renew
# Ping Kidoz Health Check
curl -m 10 --retry 5 https://health.kidoz.net/ping/your-uuid-here/$?
When pinging with HTTP POST, you can put extra diagnostic information in the request body. If the request body looks like a valid UTF-8 string, Kidoz Health Check will accept and store the first 10 kB of the request body.
In the below example, certbot's output is captured and submitted via HTTP POST:
#!/bin/sh
m=$(/usr/bin/certbot renew 2>&1)
curl -fsS -m 10 --retry 5 --data-raw "$m" https://health.kidoz.net/ping/your-uuid-here
This example uses Kidoz Health Check auto provisioning feature to create a check "on the fly" if it does not already exist. Using this technique, you can write services that automatically register with Kidoz Health Check the first time they run.
#!/bin/bash
PING_KEY=fixme-your-ping-key-here
# Use system's hostname as check's slug
SLUG=$(hostname)
# Construct a ping URL and append "?create=1" at the end:
URL=https://health.kidoz.net/ping/$PING_KEY/$SLUG?create=1
# Send a ping:
curl -m 10 --retry 5 $URL