Guide
Examples
Real-world use cases and code snippets for common alerting scenarios.
Error Alerting
Notify when uncaught errors occur in production
JavaScript
// Global error handler
process.on('uncaughtException', async (error) => {
await fetch('https://v1.talarius.io/alerts', {
method: 'POST',
headers: {
'X-API-Key': process.env.TALARIUS_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: 'Uncaught Exception',
body: `${error.name}: ${error.message}\n\n${error.stack}`,
priority: 'high',
}),
});
process.exit(1);
});Deployment Notifications
Alert your team when deployments complete
Shell
#!/bin/bash
# deploy.sh
# Your deployment commands here
npm run build
npm run deploy
# Notify on success
curl -X POST https://v1.talarius.io/alerts \
-H "X-API-Key: $TALARIUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Deployment Complete",
"body": "Version '$VERSION' deployed to '$ENVIRONMENT'"
}'Background Job Monitoring
Track when scheduled jobs complete or fail
Python
import requests
import os
from datetime import datetime
def run_daily_job():
start_time = datetime.now()
try:
# Your job logic here
process_data()
requests.post(
'https://v1.talarius.io/alerts',
headers={
'X-API-Key': os.environ['TALARIUS_API_KEY'],
'Content-Type': 'application/json',
},
json={
'title': 'Daily Job Complete',
'body': f'Processed in {(datetime.now() - start_time).seconds}s',
},
)
except Exception as e:
requests.post(
'https://v1.talarius.io/alerts',
headers={
'X-API-Key': os.environ['TALARIUS_API_KEY'],
'Content-Type': 'application/json',
},
json={
'title': 'Daily Job Failed',
'body': str(e),
'priority': 'high',
},
)
raiseDatabase Backup Status
Confirm backups completed successfully
Shell
#!/bin/bash
# backup.sh
BACKUP_FILE="backup_$(date +%Y%m%d_%H%M%S).sql"
BACKUP_SIZE=""
# Run backup
if pg_dump $DATABASE_URL > "$BACKUP_FILE"; then
BACKUP_SIZE=$(du -h "$BACKUP_FILE" | cut -f1)
# Upload to S3
aws s3 cp "$BACKUP_FILE" "s3://backups/$BACKUP_FILE"
curl -X POST https://v1.talarius.io/alerts \
-H "X-API-Key: $TALARIUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Database Backup Complete",
"body": "File: '$BACKUP_FILE' ('"$BACKUP_SIZE"')"
}'
else
curl -X POST https://v1.talarius.io/alerts \
-H "X-API-Key: $TALARIUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Database Backup Failed",
"body": "pg_dump exited with error",
"priority": "high"
}'
fiSecurity Alerts
Alert on suspicious activity like failed logins
JavaScript
// Express middleware for failed login tracking
const failedAttempts = new Map();
app.post('/login', async (req, res) => {
const { email, password } = req.body;
const ip = req.ip;
const isValid = await validateCredentials(email, password);
if (!isValid) {
const attempts = (failedAttempts.get(ip) || 0) + 1;
failedAttempts.set(ip, attempts);
if (attempts >= 5) {
await fetch('https://v1.talarius.io/alerts', {
method: 'POST',
headers: {
'X-API-Key': process.env.TALARIUS_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: 'Suspicious Login Activity',
body: `IP ${ip} has ${attempts} failed login attempts for ${email}`,
priority: 'high',
}),
});
}
return res.status(401).json({ error: 'Invalid credentials' });
}
failedAttempts.delete(ip);
// Continue with login...
});E-commerce Orders
Notify when new orders are placed
JavaScript
// Webhook handler for new orders
app.post('/webhooks/order', async (req, res) => {
const order = req.body;
await fetch('https://v1.talarius.io/alerts', {
method: 'POST',
headers: {
'X-API-Key': process.env.TALARIUS_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: `New Order #${order.id}`,
body: `${order.customer.name} ordered ${order.items.length} items for $${order.total}`,
}),
});
res.sendStatus(200);
});Tips for effective alerts
Write actionable titles
"Database connection failed" is better than "Error occurred". Include enough context to understand the issue at a glance.
Include relevant context
Add timestamps, server names, user IDs, or error traces in the body. This helps you debug faster.
Use priority wisely
Reserve "high" priority for issues that need immediate attention. Too many high-priority alerts cause alert fatigue.
Deduplicate with idempotency keys
Use idempotency keys to prevent duplicate alerts from retries or race conditions.