> For the complete documentation index, see [llms.txt](https://docs.ilert.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ilert.com/alerting/heartbeat-monitoring/cli-heartbeat-examples.md).

# CLI heartbeat examples

Ping an ilert heartbeat monitor from a shell, a backup script, or a cron job, so that only a successful run counts as a sign of life.

A ping is a single HTTP request, so every example here is one line of `curl`. What varies is *when* you send it.

All of them need the monitor's integration URL: open **Alerting** → **Heartbeat monitors**, click the monitor's row, and copy **Integration URL**. Replace `YOUR_INTEGRATION_KEY` below with the key from that URL.

{% hint style="warning" %}
`${YOUR-APIKEY}` is not a placeholder in a shell. Both bash and zsh read it as parameter substitution with a default, expand it to the literal string `APIKEY`, and cheerfully ping `https://beat.ilert.com/api/pings/APIKEY` — which answers `400`, exactly as a wrong key would. Substitute the key yourself, or read it from a variable you have set.
{% endhint %}

## Ping once

```bash
curl -fsS https://beat.ilert.com/api/pings/YOUR_INTEGRATION_KEY
```

`-f` makes curl exit non-zero on an HTTP error instead of printing the error body and reporting success, and `-sS` keeps it quiet while still showing real failures. Without `-f`, a mistyped key looks exactly like a working one.

## Ping only when the job succeeded

This is the useful shape. `&&` runs the ping only if the script exited `0`, so a backup that fails silently stops the heartbeat and pages someone:

```bash
run_backup.sh && curl -fsS https://beat.ilert.com/api/pings/YOUR_INTEGRATION_KEY
```

Putting the ping on its own line instead would report success for a job that failed — which is worse than no monitoring, because now the silence is guaranteed never to arrive.

## Report the outcome with the ping

Add a `message` query parameter and the text appears as **Last message** in the monitor's details:

```bash
run_backup.sh && curl -fsS "https://beat.ilert.com/api/pings/YOUR_INTEGRATION_KEY?message=backup+ok"
```

Quote the URL. Unquoted, zsh treats the `?` as a glob and refuses to run the command at all (`no matches found`), while bash lets a `?` through but splits the line at an `&`, backgrounding the first half and dropping every parameter after it.

## From cron

Cron runs with a minimal `PATH` and no shell profile, so use an absolute path to `curl`. Keep the key out of the crontab itself — a crontab is world-readable on many systems — by sourcing it from a file only the job's owner can read:

```bash
# /etc/ilert-heartbeat.env, chmod 600
ILERT_HEARTBEAT_KEY=YOUR_INTEGRATION_KEY
```

```cron
0 3 * * * . /etc/ilert-heartbeat.env && /usr/local/bin/run_backup.sh && /usr/bin/curl -fsS "https://beat.ilert.com/api/pings/$ILERT_HEARTBEAT_KEY"
```

Set the monitor's interval to comfortably more than the schedule — for a nightly job, 25 hours rather than 24 — or a run that starts a few minutes late raises an alert on its own.

## Verify it worked

After the first ping, the monitor's status turns from **Waiting for first ping** to **Healthy**, and **Last ping received** shows the time it arrived. If it does not, run the ping without `-s` and read the response:

```bash
curl -i https://beat.ilert.com/api/pings/YOUR_INTEGRATION_KEY
```

A `400` with `Provided key is not a valid ilert large scale heartbeat key` means the key never reached the URL intact — usually shell expansion, a truncated copy, or the key of a [legacy heartbeat alert source](/alerting/heartbeat-monitoring.md#legacy-heartbeat-alert-sources), which pings a different address.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ilert.com/alerting/heartbeat-monitoring/cli-heartbeat-examples.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
