Ready-to-use code to integrate heartbeat into your scripts.
Heartbeat integration is simple: an HTTP call at the end of your script.
Here are examples in different languages to help you get started.
Each endpoint has a specific role:
Signals that the task ran successfully.
# Signal de succes (ping)
curl -X POST https://monitao.com/api/heartbeat/ping/YOUR_PING_TOKEN \
-H "Authorization: Bearer YOUR_API_SECRET"
Signals the start of the task (optional, allows measuring duration).
# Signal de debut (start)
curl -X POST https://monitao.com/api/heartbeat/start/YOUR_PING_TOKEN \
-H "Authorization: Bearer YOUR_API_SECRET"
Signals an explicit task failure.
# Signal d'echec (fail)
curl -X POST https://monitao.com/api/heartbeat/fail/YOUR_PING_TOKEN \
-H "Authorization: Bearer YOUR_API_SECRET"
#!/bin/bash
# Script avec heartbeat MoniTao
TOKEN="YOUR_PING_TOKEN"
SECRET="YOUR_API_SECRET"
URL="https://monitao.com/api/heartbeat"
# Signal debut
curl -s -X POST "$URL/start/$TOKEN" -H "Authorization: Bearer $SECRET"
# Votre tache ici
./my_task.sh
# Verifier le code de sortie
if [ $? -eq 0 ]; then
curl -s -X POST "$URL/ping/$TOKEN" -H "Authorization: Bearer $SECRET"
else
curl -s -X POST "$URL/fail/$TOKEN" -H "Authorization: Bearer $SECRET"
fi
<?php
// PHP avec heartbeat MoniTao
$token = 'YOUR_PING_TOKEN';
$secret = 'YOUR_API_SECRET';
$baseUrl = 'https://monitao.com/api/heartbeat';
function sendHeartbeat($endpoint, $token, $secret) {
$ch = curl_init("https://monitao.com/api/heartbeat/$endpoint/$token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $secret"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// Utilisation
sendHeartbeat('start', $token, $secret);
try {
// Votre code ici
processData();
sendHeartbeat('ping', $token, $secret);
} catch (Exception $e) {
sendHeartbeat('fail', $token, $secret);
throw $e;
}
import requests
TOKEN = "YOUR_PING_TOKEN"
SECRET = "YOUR_API_SECRET"
BASE_URL = "https://monitao.com/api/heartbeat"
def heartbeat(endpoint):
return requests.post(
f"{BASE_URL}/{endpoint}/{TOKEN}",
headers={"Authorization": f"Bearer {SECRET}"}
)
# Utilisation
heartbeat("start")
try:
# Votre code ici
process_data()
heartbeat("ping")
except Exception as e:
heartbeat("fail")
raise e
Yes, the HTTP call waits for MoniTao's response (a few ms).
Add error handling or ignore the failure if the ping isn't critical.
Yes, 5-10 seconds timeout is usually sufficient.
Yes, the Authorization header with Bearer token is required to authenticate the ping.
Start free, no credit card required.