- Implement custom Python alerting system (src/alerting.py) with water level monitoring, data freshness checks, and Matrix notifications - Add complete Grafana Matrix alerting setup guide (docs/GRAFANA_MATRIX_SETUP.md) with webhook configuration, alert rules, and notification policies - Create Matrix quick start guide (docs/MATRIX_QUICK_START.md) for rapid deployment - Integrate alerting commands into main application (--alert-check, --alert-test) - Add Matrix configuration to environment variables (.env.example) - Update Makefile with alerting targets (alert-check, alert-test) - Enhance status command to show Matrix notification status - Support station-specific water level thresholds and escalation rules - Provide dual alerting approach: native Grafana alerts and custom Python system 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2.2 KiB
2.2 KiB
Quick Matrix Alerting Setup
Step 1: Get Matrix Account
- Go to https://app.element.io or install Element app
- Create account or login with existing Matrix account
Step 2: Get Access Token
Method 1: Element Web (Recommended)
- Open Element in browser: https://app.element.io
- Login to your account
- Click Settings (gear icon) → Help & About → Advanced
- Copy your "Access Token" (starts with
syt_...
or similar)
Method 2: Command Line
curl -X POST https://matrix.org/_matrix/client/v3/login \
-H "Content-Type: application/json" \
-d '{
"type": "m.login.password",
"user": "your_username",
"password": "your_password"
}'
Step 3: Create Alert Room
- In Element, click "+" to create new room
- Name: "Water Level Alerts"
- Set to Private
- Copy the room ID from room settings (format:
!roomid:matrix.org
)
Step 4: Configure .env File
Add these to your .env
file:
# Matrix Alerting Configuration
MATRIX_HOMESERVER=https://matrix.org
MATRIX_ACCESS_TOKEN=syt_your_access_token_here
MATRIX_ROOM_ID=!your_room_id:matrix.org
# Grafana Integration (optional)
GRAFANA_URL=http://localhost:3000
Step 5: Test Configuration
# Test Matrix connection
uv run python run.py --alert-test
# Check system status (shows Matrix config)
uv run python run.py --status
# Run alert check
uv run python run.py --alert-check
Example Alert Message
When thresholds are exceeded, you'll receive messages like:
🌊 **WATER LEVEL ALERT**
**Station:** P.1 (สถานีเชียงใหม่)
**Alert Type:** Critical Water Level
**Severity:** CRITICAL
**Current Level:** 6.75m
**Threshold:** 6.0m
**Difference:** +0.75m
**Discharge:** 450.2 cms
**Time:** 2025-09-26 14:30:00
📈 View dashboard: http://localhost:3000
Cron Job Setup (Optional)
Add to crontab for automatic alerting:
# Check water levels every 15 minutes
*/15 * * * * cd /path/to/monitor && uv run python run.py --alert-check >> alerts.log 2>&1
Troubleshooting
- 403 Error: Check Matrix access token is valid
- Room Not Found: Verify room ID includes
!
prefix and:homeserver.com
suffix - No Alerts: Check database has recent data with
uv run python run.py --status