Examples
Real-world examples of using NotifyHero for various use cases.
Monitoring & Alerts
Server Down Alert
Monitor a website and get notified when it goes down:
#!/bin/bash
if ! curl -s --head https://example.com | head -n 1 | grep "200 OK" > /dev/null; then
curl -H "Priority: urgent" \
-H "Tags: warning" \
-d "example.com is DOWN!" \
https://app.notifyhero.com/server-alerts
fi
Add to crontab to run every minute:
* * * * * /path/to/check-website.sh
Disk Space Warning
#!/bin/bash
THRESHOLD=90
USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ "$USAGE" -gt "$THRESHOLD" ]; then
curl -H "Priority: high" \
-H "Tags: warning,floppy_disk" \
-d "Disk usage is at ${USAGE}%!" \
https://app.notifyhero.com/server-alerts
fi
CPU/Memory Alert
#!/bin/bash
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d. -f1)
MEM=$(free | grep Mem | awk '{printf("%.0f", $3/$2 * 100.0)}')
if [ "$CPU" -gt 90 ] || [ "$MEM" -gt 90 ]; then
curl -H "Priority: high" \
-d "High resource usage: CPU ${CPU}%, Memory ${MEM}%" \
https://app.notifyhero.com/server-alerts
fi
CI/CD Integration
GitHub Actions
name: Build and Notify
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: npm run build
- name: Notify on success
if: success()
run: |
curl -H "Tags: white_check_mark" \
-d "Build succeeded for ${{ github.repository }}" \
https://app.notifyhero.com/builds
- name: Notify on failure
if: failure()
run: |
curl -H "Priority: high" \
-H "Tags: x" \
-d "Build FAILED for ${{ github.repository }}" \
https://app.notifyhero.com/builds
Jenkins
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'make build'
}
}
}
post {
success {
sh '''
curl -d "Jenkins build #${BUILD_NUMBER} succeeded" \
https://app.notifyhero.com/jenkins
'''
}
failure {
sh '''
curl -H "Priority: high" \
-d "Jenkins build #${BUILD_NUMBER} FAILED" \
https://app.notifyhero.com/jenkins
'''
}
}
}
GitLab CI
notify:
stage: deploy
script:
- |
curl -H "Tags: rocket" \
-d "Deployed ${CI_COMMIT_SHORT_SHA} to production" \
https://app.notifyhero.com/deploys
Backup Notifications
Backup Script
#!/bin/bash
BACKUP_DIR="/backup"
DATE=$(date +%Y-%m-%d)
# Run backup
tar -czf "$BACKUP_DIR/backup-$DATE.tar.gz" /data
if [ $? -eq 0 ]; then
SIZE=$(du -h "$BACKUP_DIR/backup-$DATE.tar.gz" | cut -f1)
curl -H "Tags: floppy_disk,white_check_mark" \
-d "Backup completed: backup-$DATE.tar.gz ($SIZE)" \
https://app.notifyhero.com/backups
else
curl -H "Priority: urgent" \
-H "Tags: x" \
-d "Backup FAILED on $DATE" \
https://app.notifyhero.com/backups
fi
Database Backup
#!/bin/bash
pg_dump mydb > /backup/mydb.sql 2>&1
if [ $? -eq 0 ]; then
curl -d "Database backup completed" https://app.notifyhero.com/backups
else
curl -H "Priority: high" -d "Database backup failed!" https://app.notifyhero.com/backups
fi
Long-Running Commands
Notify When Done
# Run a long command and notify when done
make build && curl -d "Build finished!" https://app.notifyhero.com/commands
# Or capture the result
./long-script.sh; curl -d "Script exited with code $?" https://app.notifyhero.com/commands
Training Complete (ML)
import requests
# After training
model.fit(X_train, y_train)
requests.post(
"https://app.notifyhero.com/ml-training",
data=f"Training complete! Accuracy: {accuracy:.2%}",
headers={"Tags": "brain,white_check_mark"}
)
Home Automation
Doorbell
# When doorbell is pressed
curl -H "Title: Doorbell" \
-H "Tags: bell" \
-H "Priority: high" \
-H "Click: https://camera.example.com" \
-d "Someone is at the door!" \
https://app.notifyhero.com/home
Temperature Alert
import requests
temp = get_temperature()
if temp > 30:
requests.post(
"https://app.notifyhero.com/home",
data=f"Temperature is {temp}°C - too hot!",
headers={
"Priority": "high",
"Tags": "thermometer,warning"
}
)
Package Delivered
# Triggered by mailbox sensor
curl -H "Title: Package Alert" \
-H "Tags: package" \
-d "A package was delivered!" \
https://app.notifyhero.com/home
Security
SSH Login Alert
Add to /etc/ssh/sshrc:
curl -H "Tags: lock" \
-d "SSH login: $USER from $SSH_CLIENT" \
https://app.notifyhero.com/security
Failed Login Attempt
Using fail2ban:
[Definition]
actionban = curl -H "Priority: high" -H "Tags: warning" \
-d "Banned IP: <ip> for <name>" \
https://app.notifyhero.com/security
Finance
Stock Price Alert
import requests
price = get_stock_price("AAPL")
if price < 150:
requests.post(
"https://app.notifyhero.com/stocks",
data=f"AAPL is at ${price} - time to buy?",
headers={"Tags": "chart_with_downwards_trend,money_with_wings"}
)
Crypto Alert
PRICE=$(curl -s "https://api.coinbase.com/v2/prices/BTC-USD/spot" | jq -r '.data.amount')
if (( $(echo "$PRICE > 50000" | bc -l) )); then
curl -H "Tags: rocket,money_with_wings" \
-d "BTC is above \$50k! Currently: \$$PRICE" \
https://app.notifyhero.com/crypto
fi
Cron Job Monitoring
Heartbeat Pattern
# Add to your cron job
0 * * * * /path/to/hourly-job.sh && curl -d "Hourly job ran successfully" https://app.notifyhero.com/cron
Dead Man's Switch
If your cron job should run every hour but you want to be notified if it doesn't:
# Job sends heartbeat
0 * * * * /path/to/job.sh && curl https://app.notifyhero.com/heartbeat
# External monitor checks for heartbeat
# If no message in 2 hours, alert