Current State
Three independent alert scripts manually deployed to monitor11:
ispconfig-login-alert (email + Matrix) - alerts on ANY ISPConfig login
matrix-synapse-alert (Matrix only) - alerts on Matrix Synapse errors
fail2ban-alert (email only) - alerts on high ban rate
Deployment: Manual scp + systemd setup on monitor11
Location: Scripts in /usr/local/bin/, configs in /etc/{service}/, systemd units manually created
Desired State
Unified alert_notifier role in solti-ensemble that:
- Deploys all alert scripts via Ansible templates
- Shares common utilities (
matrix-send.py, email helpers)
- Configurable per-alert via role variables
- Idempotent deployment with proper systemd timer management
- Version controlled and repeatable
Benefits
- Repeatable deployments - Deploy to new monitoring servers easily
- Easier to add new alerts - Template pattern for new alert types
- Consistent configuration - All alerts use same variable structure
- Version controlled - Track changes to alert logic over time
- Testing - Molecule scenarios for alert deployment
Design Questions to Answer
- Shared utility strategy: Should
matrix-send.py be a shared utility or per-alert?
- Template vs. scripts: Alert templates (Jinja2) vs. separate Python scripts?
- Dependencies: How to handle alert-specific Python dependencies (requests, yaml)?
- State file management: Where to store state files, cleanup strategy?
- Alert toggles: Should alerts be independently enabled/disabled via variables?
- Credentials: How to pass Matrix tokens, SMTP passwords securely?
- Multiple targets: Support deploying different alerts to different hosts?
Proposed Architecture
solti-ensemble/roles/alert_notifier/
├── defaults/main.yml # Default variables for all alerts
├── templates/
│ ├── matrix-send.py.j2 # Shared Matrix notification utility
│ ├── ispconfig-login-alert.py.j2
│ ├── matrix-synapse-alert.py.j2
│ ├── fail2ban-alert.py.j2
│ └── alert-wrapper.sh.j2 # Generic wrapper for env vars
├── tasks/
│ ├── main.yml # Orchestrates alert deployment
│ ├── matrix-send.yml # Deploy matrix-send.py utility
│ ├── ispconfig-alert.yml # Deploy ISPConfig alert
│ ├── matrix-synapse-alert.yml
│ └── fail2ban-alert.yml
└── molecule/
└── default/
└── converge.yml # Test alert deployment
Example Usage
- name: Deploy alerts to monitor11
hosts: monitor11
roles:
- role: jackaltx.solti_ensemble.alert_notifier
vars:
# Matrix notification config
alert_matrix_enabled: true
alert_matrix_homeserver: "https://matrix-web.jackaltx.com"
alert_matrix_token: "{{ vault_matrix_token }}"
alert_matrix_room: "#solti-verify:jackaltx.com"
# ISPConfig alert
ispconfig_alert_enabled: true
ispconfig_alert_loki_url: "http://localhost:3100"
ispconfig_alert_email_enabled: true
ispconfig_alert_smtp_host: "mail.lavnet.net"
# Matrix Synapse alert
matrix_synapse_alert_enabled: true
matrix_synapse_alert_check_interval: 10
# Fail2ban alert
fail2ban_alert_enabled: true
fail2ban_alert_threshold: 50
fail2ban_alert_matrix_enabled: false # Email only
Testing Strategy
- Molecule scenario: Deploy all alerts to test container
- Verify systemd timers: Check timers are created and enabled
- Mock Loki responses: Test alert logic with fake data
- Matrix notification test: Verify matrix-send.py works
- Idempotency: Run role twice, ensure no changes
Related
- Existing role:
solti-ensemble/roles/alert_notifier (currently has fail2ban-alert only)
- Documentation:
mylab/docs/matrix-notifications.md
- Manual deployment: Scripts currently on monitor11 in
/usr/local/bin/
- Matrix collection:
solti-matrix-mgr for Matrix API integration
Acceptance Criteria
Current State
Three independent alert scripts manually deployed to monitor11:
ispconfig-login-alert(email + Matrix) - alerts on ANY ISPConfig loginmatrix-synapse-alert(Matrix only) - alerts on Matrix Synapse errorsfail2ban-alert(email only) - alerts on high ban rateDeployment: Manual scp + systemd setup on monitor11
Location: Scripts in
/usr/local/bin/, configs in/etc/{service}/, systemd units manually createdDesired State
Unified
alert_notifierrole in solti-ensemble that:matrix-send.py, email helpers)Benefits
Design Questions to Answer
matrix-send.pybe a shared utility or per-alert?Proposed Architecture
Example Usage
Testing Strategy
Related
solti-ensemble/roles/alert_notifier(currently has fail2ban-alert only)mylab/docs/matrix-notifications.md/usr/local/bin/solti-matrix-mgrfor Matrix API integrationAcceptance Criteria