Toevoegen aan cron job
Doel: Een heartbeat URL toevoegen aan een bestaande cron job of script, zodat ePulz.io na elke succesvolle uitvoering een "ik leef nog" ping ontvangt.
Principe
U roept de heartbeat URL aan na succesvolle voltooiing van de taak. Als het script faalt, wordt de URL niet aangeroepen, ePulz.io merkt de ontbrekende ping op en stuurt u een melding.
Bash / shell cron
Voeg de curl aanroep toe aan het einde van uw cron regel verbonden met de operator &&:
# /etc/crontab of crontab -e
0 3 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 \
https://epulz.io/heartbeat/Qs78OPNIIsCF_-Vj > /dev/null
Curl flags:
-f= fail bij non-2xx response (curl retourneert error)-s= silent (geen progress)-S= maar toont errors (combinatie met -s)-m 10= max-time 10 seconden (timeout)> /dev/null= response vult de cron log niet
Python
Voor Python scripts voegt u de aanroep toe via requests of urllib:
import os
import requests
HEARTBEAT_URL = os.environ.get("HEARTBEAT_URL")
def sync_data():
# ... uw logica ...
pass
try:
sync_data()
# Heartbeat wordt alleen verzonden als sync_data() geen exception raised
if HEARTBEAT_URL:
requests.get(HEARTBEAT_URL, timeout=10)
except Exception as e:
# Heartbeat wordt niet verzonden - ePulz.io waarschuwt u
print(f"Sync failed: {e}")
raise
Zonder externe bibliotheek, alleen met de standaard:
import urllib.request
# Na succesvolle voltooiing van de taak
urllib.request.urlopen("https://epulz.io/heartbeat/Qs78OPNIIsCF_-Vj", timeout=10)
Node.js
const HEARTBEAT_URL = process.env.HEARTBEAT_URL;
async function nightlyJob() {
await processInvoices();
// Heartbeat pas na succesvolle voltooiing
await fetch(HEARTBEAT_URL, { signal: AbortSignal.timeout(10000) });
}
nightlyJob().catch(err => {
console.error(err);
process.exit(1); // Heartbeat wordt niet verzonden, ePulz.io waarschuwt u
});
Docker / systemd timer
Voor een systemd timer voegt u ExecStartPost toe aan het .service bestand:
# /etc/systemd/system/db-backup.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
ExecStartPost=/usr/bin/curl -fsS -m 10 https://epulz.io/heartbeat/Qs78OPNIIsCF_-Vj
ExecStartPost wordt alleen uitgevoerd als ExecStart succesvol was.
PHP / Laravel scheduler
// app/Console/Kernel.php
$schedule->command('backup:run')
->daily()
->thenPing('https://epulz.io/heartbeat/Qs78OPNIIsCF_-Vj');
Laravel heeft een ingebouwde methode thenPing() precies voor dit doel.
Geavanceerd: ping aan het begin en aan het einde
Voor een grondigere detectie kunt u ook een "start" ping versturen (taak is gestart) - daarmee onderscheidt u "taak is helemaal niet gestart" van "taak is vastgelopen":
# Start ping
curl -fsS -m 10 https://epulz.io/heartbeat/Qs78OPNIIsCF_-Vj/start > /dev/null
# Uw taak
/usr/local/bin/backup.sh
EXIT_CODE=$?
# Done ping met exit code
curl -fsS -m 10 "https://epulz.io/heartbeat/Qs78OPNIIsCF_-Vj?exit=$EXIT_CODE" > /dev/null
Test - simulatie van één uitvoering
Voor opname in de cron test de URL handmatig:
$ curl -fsS https://epulz.io/heartbeat/Qs78OPNIIsCF_-Vj
OK
Na een succesvolle aanroep ziet u in het ePulz.io dashboard de status van de monitor veranderen van Pending naar OK.