Configures automated infrastructure monitoring with mobile alerts (ntfy.sh and Home Assistant) and implements auto-recovery for common failures...
Works with infrastructure-monitor.sh script, systemd timer, ntfy.sh push notifications,
Complete setup and configuration of automated infrastructure monitoring with mobile push notifications and auto-recovery capabilities.
Quick setup for monitoring (5 minutes):
# 1. Create unique ntfy topic
TOPIC="infra-$(openssl rand -hex 8)"
echo "Your topic: $TOPIC"
# 2. Add to .env
echo "ALERT_ENABLED=true" >> /home/dawiddutoit/projects/network/.env
echo "NTFY_SERVER=https://ntfy.sh" >> /home/dawiddutoit/projects/network/.env
echo "NTFY_TOPIC=$TOPIC" >> /home/dawiddutoit/projects/network/.env
echo "AUTO_RECOVER=true" >> /home/dawiddutoit/projects/network/.env
# 3. Install systemd service
sudo cp /home/dawiddutoit/projects/network/systemd/infrastructure-monitor.* /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now infrastructure-monitor.timer
# 4. Test
/home/dawiddutoit/projects/network/scripts/infrastructure-monitor.sh
Then install ntfy app on phone and subscribe to your topic.
Explicit Triggers:
Implicit Triggers:
Debugging Triggers:
Install app:
Subscribe to topic:
infra-YOUR-RANDOM-ID (you'll generate this in step 3.2)https://ntfy.shNote: You need the topic ID from step 3.2 before subscribing. Come back here after generating it.
Generate unique topic ID:
TOPIC="infra-$(openssl rand -hex 8)"
echo "Your unique topic: $TOPIC"
Save this topic ID - you'll use it in the ntfy app.
Add monitoring configuration to .env:
# Navigate to project directory
cd /home/dawiddutoit/projects/network
# Add monitoring variables
cat >> .env << EOF
# Monitoring & Alerts
ALERT_ENABLED=true
NTFY_SERVER=https://ntfy.sh
NTFY_TOPIC=$TOPIC
AUTO_RECOVER=true
EOF
Verify configuration:
grep -A4 "Monitoring & Alerts" /home/dawiddutoit/projects/network/.env
Expected:
# Monitoring & Alerts
ALERT_ENABLED=true
NTFY_SERVER=https://ntfy.sh
NTFY_TOPIC=infra-a3f7d92b4c8e1f56
AUTO_RECOVER=true
Configuration options:
| Variable | Purpose | Default |
|---|---|---|
ALERT_ENABLED |
Enable mobile push notifications | false |
NTFY_SERVER |
ntfy.sh server URL | https://ntfy.sh |
NTFY_TOPIC |
Unique topic for your alerts | None (required) |
AUTO_RECOVER |
Enable automatic recovery | true |
To disable auto-recovery but keep alerts:
# Edit .env
nano /home/dawiddutoit/projects/network/.env
# Change: AUTO_RECOVER=false
Install systemd service and timer to run monitoring every 5 minutes:
# Copy service files
sudo cp /home/dawiddutoit/projects/network/systemd/infrastructure-monitor.service /etc/systemd/system/
sudo cp /home/dawiddutoit/projects/network/systemd/infrastructure-monitor.timer /etc/systemd/system/
# Reload systemd
sudo systemctl daemon-reload
# Enable and start timer
sudo systemctl enable infrastructure-monitor.timer
sudo systemctl start infrastructure-monitor.timer
Verify timer is active:
# Check timer status
systemctl list-timers infrastructure-monitor.timer
# Check service status
sudo systemctl status infrastructure-monitor.timer
Expected:
ā infrastructure-monitor.timer - Run infrastructure monitoring every 5 minutes
Loaded: loaded (/etc/systemd/system/infrastructure-monitor.timer; enabled)
Active: active (waiting) since...
Timer configuration:
Test monitoring script:
# Run monitoring manually
/home/dawiddutoit/projects/network/scripts/infrastructure-monitor.sh
Expected output shows:
Test alert delivery:
Within 30 seconds, you should receive push notification on phone with infrastructure status.
If no notification received:
Check ntfy topic subscription:
# Test sending to topic directly
curl -d "Test from infrastructure monitoring" https://ntfy.sh/$TOPIC
If direct curl works but monitoring doesn't:
Why use Home Assistant integration:
Prerequisites:
Step 1: Create Long-Lived Access Token
Step 2: Find Notification Service Name
notify.mobile_app_your_phoneStep 3: Add to .env
# Edit .env
nano /home/dawiddutoit/projects/network/.env
# Add HA configuration
HA_NOTIFICATIONS_ENABLED=true
HA_BASE_URL=http://192.168.68.123:8123
HA_ACCESS_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
HA_NOTIFY_SERVICE=notify.mobile_app_your_phone
Step 4: Test HA Notifications
# Run monitoring (should send to both ntfy and HA)
/home/dawiddutoit/projects/network/scripts/infrastructure-monitor.sh
Check you receive notification in Home Assistant companion app.
Troubleshooting HA notifications:
# Test HA API access
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://192.168.68.123:8123/api/
# Test notification service
curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message": "Test from infrastructure monitoring"}' \
http://192.168.68.123:8123/api/services/notify/mobile_app_your_phone
Monitor logs to see auto-recovery in action:
# View live monitoring logs
sudo journalctl -u infrastructure-monitor.service -f
# Or check persistent log
tail -f /var/log/infrastructure-monitor.log
Auto-recovery capabilities:
| Issue | Detection | Recovery Action |
|---|---|---|
| Stuck cloudflared | No registrations in 10 min | Restart cloudflared container |
| Docker network isolation | Ping fails between containers | Recreate bridge network |
| Inactive Ethernet | WiFi used instead of eth0 | Activate Ethernet connection |
| Service failures | HTTP health checks fail | Restart affected containers |
Test auto-recovery:
# Simulate stuck tunnel
docker stop cloudflared
# Wait 5 minutes (next monitoring run)
# Check logs - should show tunnel restarted
# Verify tunnel recovered
docker ps | grep cloudflared
docker logs cloudflared | grep "Registered tunnel"
View systemd service logs:
# Live monitoring logs
sudo journalctl -u infrastructure-monitor.service -f
# Last 50 lines
sudo journalctl -u infrastructure-monitor.service -n 50
# Logs from today
sudo journalctl -u infrastructure-monitor.service --since today
# Logs with timestamps
sudo journalctl -u infrastructure-monitor.service -o short-iso
View persistent log file:
# Live tail
tail -f /var/log/infrastructure-monitor.log
# Last 100 lines
tail -100 /var/log/infrastructure-monitor.log
# Search for errors
grep -i error /var/log/infrastructure-monitor.log
# Search for recoveries
grep -i "recovered" /var/log/infrastructure-monitor.log
Check timer schedule:
# Show next run time
systemctl list-timers infrastructure-monitor.timer
# Show timer configuration
systemctl cat infrastructure-monitor.timer
Monitoring controls:
# Stop monitoring temporarily
sudo systemctl stop infrastructure-monitor.timer
# Restart monitoring
sudo systemctl start infrastructure-monitor.timer
# Disable monitoring (survives reboot)
sudo systemctl disable infrastructure-monitor.timer
# Re-enable monitoring
sudo systemctl enable infrastructure-monitor.timer
| File | Purpose |
|---|---|
references/reference.md |
Monitoring architecture, recovery strategies, ntfy.sh details |
examples/examples.md |
Example configurations, alert formats, log outputs |
scripts/test-notifications.sh |
Test script for alert delivery |
Success:
Partial Success:
Failure Indicators: