Almost every backend starts with a single Slack webhook URL hardcoded in an environment variable. Six months later, that single webhook has turned into a tangle of Firebase Admin SDK credentials, SMTP retry loops, Telegram bot tokens, and conditional routing logic scattered across three microservices.
When you need to add a new on-call engineer or route high-priority alerts to WhatsApp instead of email, you end up modifying application code and redeploying services. With AlertHub, your code emits a single standard POST request using each language's built-in HTTP client—zero third-party SDK dependencies required—while notification profiles handle the multi-channel fan-out.
1. Quickstart: Send an Event in 10 Seconds
Every event follows the same flat JSON contract sent to https://alerthub.io/api/event/YOUR_USER_ID with your X-API-KEY header. Switch between languages below to test an event directly from your terminal or codebase:
curl -X POST https://alerthub.io/api/event/YOUR_USER_ID \
-H "X-API-KEY: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Deployment failed: api-gateway",
"body": "Container exited with code 1 on prod-eu-1 during migration step.",
"status": "error",
"priority": "high",
"source": "ci-deploy"
}'
package main
import (
"bytes"
"context"
"encoding/json"
"net/http"
"time"
)
type AlertEvent struct {
Title string `json:"title"`
Body string `json:"body"`
Status string `json:"status"`
Priority string `json:"priority"`
Source string `json:"source"`
}
func sendAlert(ctx context.Context, userID, apiKey string, ev AlertEvent) error {
payload, err := json.Marshal(ev)
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(ctx, 4*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://alerthub.io/api/event/"+userID, bytes.NewReader(payload))
if err != nil {
return err
}
req.Header.Set("X-API-KEY", apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}
import urllib.request
import json
def send_alert(user_id: str, api_key: str, title: str, body: str, status: str = "info", priority: str = "normal"):
data = json.dumps({
"title": title,
"body": body,
"status": status,
"priority": priority,
"source": "python-service",
}).encode("utf-8")
req = urllib.request.Request(
f"https://alerthub.io/api/event/{user_id}",
data=data,
headers={
"X-API-KEY": api_key,
"Content-Type": "application/json",
},
method="POST",
)
with urllib.request.urlopen(req, timeout=4) as resp:
return resp.status
export async function sendAlert({ userId, apiKey, title, body, status = "info", priority = "normal" }) {
const res = await fetch(`https://alerthub.io/api/event/${userId}`, {
method: "POST",
headers: {
"X-API-KEY": apiKey,
"Content-Type": "application/json",
},
body: JSON.stringify({
title,
body,
status,
priority,
source: "node-api",
}),
signal: AbortSignal.timeout(4000),
});
if (!res.ok) {
throw new Error(`AlertHub ingestion failed: HTTP ${res.status}`);
}
}
#!/usr/bin/env bash
curl -fsS -m 5 -X POST "https://alerthub.io/api/event/${ALERTHUB_USER_ID}" \
-H "X-API-KEY: ${ALERTHUB_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"title": "Backup completed: postgres-main",
"body": "Uploaded 4.2 GB snapshot to off-site S3 bucket in 18s.",
"status": "success",
"priority": "low",
"source": "backup-runner"
}' > /dev/null
4–5 second timeout. Notification calls should never stall a user-facing checkout or block a worker shutdown if an upstream network blip occurs.
2. Scenario 1: Payment & Signup Events (Node.js)
High-value business events, like an enterprise subscription upgrade or a failed Stripe renewal, deserve immediate visibility without digging through application logs. Inside your webhook handler, emit a structured alert right after updating your database:
async function handlePaymentFailed(invoice) {
const amount = (invoice.amount_due / 100).toFixed(2);
const currency = invoice.currency.toUpperCase();
// Fire-and-forget alert to Mobile Push + Slack via AlertHub
await fetch(`https://alerthub.io/api/event/${process.env.ALERTHUB_USER_ID}`, {
method: "POST",
headers: {
"X-API-KEY": process.env.ALERTHUB_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
title: `Payment failed: ${currency} ${amount}`,
body: `Customer ${invoice.customer_email} failed renewal on invoice ${invoice.id} (attempt ${invoice.attempt_count}).`,
status: "warning",
priority: "high",
source: "stripe-billing",
profile: "d45j7kgoaiiuko7h08v0",
}),
signal: AbortSignal.timeout(4000),
}).catch((err) => console.error("AlertHub dispatch error:", err));
}
By passing the optional "profile": "d45j7kgoaiiuko7h08v0" field, you can route billing notifications to a dedicated Slack channel and your phone without mixing them into infrastructure error streams.
3. Scenario 2: Unhandled Exceptions & Worker Panics (Go)
Background goroutines and queue consumers often crash silently when an unexpected nil pointer or malformed payload triggers a panic. Wrapping your worker entry point with a defer recover() helper captures the panic message and stack trace, sends an urgent alert, and then re-panics cleanly so your container supervisor restarts the process:
package worker
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"runtime/debug"
"time"
)
func RunWithPanicAlert(workerName string, fn func()) {
defer func() {
if r := recover(); r != nil {
stack := string(debug.Stack())
if len(stack) > 1200 {
stack = stack[:1200] + "\n...truncated"
}
payload, _ := json.Marshal(map[string]string{
"title": fmt.Sprintf("Worker panic: %s", workerName),
"body": fmt.Sprintf("Panic: %v\n\nStack trace:\n%s", r, stack),
"status": "error",
"priority": "high",
"source": workerName,
})
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(
ctx,
http.MethodPost,
"https://alerthub.io/api/event/"+os.Getenv("ALERTHUB_USER_ID"),
bytes.NewReader(payload),
)
if err == nil {
req.Header.Set("X-API-KEY", os.Getenv("ALERTHUB_API_KEY"))
req.Header.Set("Content-Type", "application/json")
if resp, err := http.DefaultClient.Do(req); err == nil {
resp.Body.Close()
}
}
// Re-panic after alerting so Docker/systemd restarts the service
panic(r)
}
}()
fn()
}
4. Scenario 3: Queue Depth & Disk Threshold Warnings (Python)
The best outages are the ones you prevent before users notice. A lightweight health probe running inside your worker or via cron can check your Redis/Valkey queue backlog and local disk usage, escalating from warning to error as thresholds worsen:
import json
import os
import shutil
import socket
import urllib.request
USER_ID = os.environ["ALERTHUB_USER_ID"]
API_KEY = os.environ["ALERTHUB_API_KEY"]
def notify(title: str, body: str, status: str, priority: str):
payload = json.dumps({
"title": title,
"body": body,
"status": status,
"priority": priority,
"source": "infra-probe",
}).encode("utf-8")
req = urllib.request.Request(
f"https://alerthub.io/api/event/{USER_ID}",
data=payload,
headers={"X-API-KEY": API_KEY, "Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(req, timeout=4):
pass
def check_disk_usage(path: str = "/", warn_pct: int = 85, crit_pct: int = 95):
total, used, free = shutil.disk_usage(path)
used_pct = round((used / total) * 100, 1)
free_gb = round(free / (1024 ** 3), 1)
host = socket.gethostname()
if used_pct >= crit_pct:
notify(
title=f"CRITICAL disk usage ({used_pct}%) on {host}",
body=f"Mount {path} is at {used_pct}% capacity ({free_gb} GB free). Immediate cleanup required.",
status="error",
priority="high",
)
elif used_pct >= warn_pct:
notify(
title=f"High disk usage ({used_pct}%) on {host}",
body=f"Mount {path} crossed {warn_pct}% threshold ({free_gb} GB remaining).",
status="warning",
priority="medium",
)
if __name__ == "__main__":
check_disk_usage("/")
Because every event includes status (info, success, warning, error) and priority (low, normal, high), you can inspect all incoming events in real time on your live AlertHub dashboard and customize notifications profiles that meet your needs.