Examples
Copy-paste integrations: shell scripts, GitHub Actions, Node.js and Python.
Shell script
Report success and failure from a backup script. Use an idempotency key so a retry does not create a duplicate.
backup.sh
BASH
#!/usr/bin/env bash
set -euo pipefail
API_URL="https://your-instance.example.com"
API_KEY="${BELLCAST_API_KEY:?set BELLCAST_API_KEY}"
notify() {
curl -fsS -X POST "$API_URL/api/v1/publish/backups" \
-H "X-API-Key: $API_KEY" \
-H "Title: $1" \
-H "Priority: $2" \
-H "Idempotency-Key: backup-$(date +%F)-$3" \
-d "$4"
}
if pg_dump | gzip > backup.sql.gz; then
notify "Backup finished" "default" ok \
"Saved $(du -h backup.sql.gz | cut -f1) on $(hostname)"
else
notify "Backup failed" "max" failed \
"pg_dump failed on $(hostname)"
exit 1
fiGitHub Actions
.github/workflows/notify.yml
YAML
- name: Notify Bellcast
if: failure()
env:
BELLCAST_API_KEY: ${{ secrets.BELLCAST_API_KEY }}
run: |
curl -fsS -X POST https://your-instance.example.com/api/v1/publish/ci \
-H "X-API-Key: $BELLCAST_API_KEY" \
-H "Title: CI failed" \
-H "Priority: high" \
-H "Click: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-d "${{ github.workflow }} failed on ${{ github.ref_name }}"Store the key as a repository secret named BELLCAST_API_KEY.
Node.js
notify.mjs
JAVASCRIPT
const API_URL = process.env.BELLCAST_URL
const API_KEY = process.env.BELLCAST_API_KEY
await fetch(`${API_URL}/api/v1/publish/alerts`, {
method: "POST",
headers: {
"X-API-Key": API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Payment failed",
body: `Customer ${customerId} could not be charged.`,
priority: "high",
tags: ["billing"],
click: "https://dashboard.example.com/billing",
}),
})Python
notify.py
PYTHON
import os
import requests
API_URL = os.environ["BELLCAST_URL"]
API_KEY = os.environ["BELLCAST_API_KEY"]
requests.post(
f"{API_URL}/api/v1/publish/alerts",
headers={"X-API-Key": API_KEY},
data="CPU at 98% for 5 minutes.",
timeout=10,
# Title, Priority, Tags and Click can also be sent as headers.
)Wrap publishing in a small helper class if you call it from many places, and always set a timeout so a slow notification cannot block the job it reports on.