---
title: Heartbeats from cron
description: Ping a ZevSight heartbeat URL from cron jobs, scripts and workers, with start, success and failure pings.
url: https://docs.zevsight.com/send/heartbeats
---

# Heartbeats from cron

> Ping a ZevSight heartbeat URL from cron jobs, scripts and workers, with start, success and failure pings.

A heartbeat monitor expects a ping at least once per interval. If a ping is late, or a job reports a failure, ZevSight raises an alert. Create the monitor first (see [Heartbeats](/monitor/heartbeats)) and copy its ping URL. It looks like this:

```text
https://ingest.zevsight.com/h/<PING_TOKEN>
```

The token in the URL is the credential. No header is needed. Treat the URL as a secret: anyone who has it can send pings.

## Ping routes

| Route | Meaning |
|---|---|
| `GET` or `POST /h/<PING_TOKEN>` | Success. |
| `GET` or `POST /h/<PING_TOKEN>/start` | The job started. The next success or failure ping records how long it ran. |
| `GET` or `POST /h/<PING_TOKEN>/fail` | The job failed. Alerts right away, without waiting for the grace period. |

A `POST` body (plain text, up to 8 KiB) is stored as the ping's note: an exit code, a row count, an error. Longer notes are truncated, not refused.

## Cron

Ping when the job succeeds:

```bash
# m h dom mon dow  command
0 3 * * *  /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 https://ingest.zevsight.com/h/<PING_TOKEN> > /dev/null
```

Report start, success and failure, with the exit code as the note:

```bash
#!/usr/bin/env bash
URL=https://ingest.zevsight.com/h/<PING_TOKEN>

curl -fsS -m 10 --retry 3 "$URL/start" > /dev/null
/usr/local/bin/backup.sh
code=$?
if [ $code -eq 0 ]; then
  curl -fsS -m 10 --retry 3 "$URL" > /dev/null
else
  curl -fsS -m 10 --retry 3 --data "exit $code" "$URL/fail" > /dev/null
fi
exit $code
```

## Node.js

```js

await withHeartbeat(process.env.ZEVSIGHT_HEARTBEAT_URL, () => runNightlyExport());
```

See [Node.js SDK](/send/nodejs#heartbeats).

## Python

```python
import os, urllib.request

url = os.environ["ZEVSIGHT_HEARTBEAT_URL"]
try:
    run_job()
    urllib.request.urlopen(url, timeout=10)
except Exception as e:
    urllib.request.urlopen(urllib.request.Request(url + "/fail", data=str(e)[:8000].encode(), method="POST"), timeout=10)
    raise
```

## Responses

| Status | Meaning |
|---|---|
| `200` | Recorded. Body `OK`. |
| `404` `NOT_FOUND` | No monitor has this URL. It may have been rotated or deleted. |
| `421` `WRONG_REGION` | The monitor lives in another region's ingest host. |
| `429` `RATE_LIMITED` | More than 2 pings a second for this monitor (bursts of 10 are fine). Wait for `Retry-After`. |
| `503` `UNAVAILABLE` | Try again after `Retry-After`. |

Pings are accepted at every quota level and in every subscription state, so a full monthly log quota never silences your cron alerts. A paused monitor still records pings but raises nothing.

Rotating a monitor's token in the dashboard stops the old URL at once. Update your jobs at the same time.
