AlertManager
A flexible alert management system with SQLite backend that can be used as a library in Python applications.
About
AlertManager is developed by Evolvis, a company specializing in intelligent automation and monitoring solutions. This library provides a robust foundation for managing alerts in any Python application, with a focus on flexibility, performance, and ease of use.
Author
Alban Maxhuni, PhD
Email: a.maxhuni@evolvis.ai
Features
- SQLite-based alert storage with connection pooling
- Configurable through YAML files
- Support for different alert types and severities
- Alert acknowledgment and resolution tracking
- Metadata support for additional information
- Automatic cleanup of old alerts
- Configurable logging with enable/disable option
- Advanced statistics and metrics
- Trend analysis and reporting
- Generic BaseManager for extensible data management
- Automatic timestamp handling
- JSON field serialization/deserialization
- Bulk operations support
- Migration support for database schema
Installation
pip install alertmanager
Usage
Basic Usage
from alertmanager import AlertManager
# Initialize with default configuration
alert_manager = AlertManager()
# Create an alert
alert_id = alert_manager.create_alert(
title="Disk space is running low",
description="Disk usage is above 85%",
severity="warning"
)
# Get active alerts
alerts = alert_manager.get_alerts(status="active")
# Acknowledge an alert
alert_manager.acknowledge_alert(alert_id, "admin")
# Resolve an alert
alert_manager.resolve_alert(alert_id, "admin")
Advanced Usage
# Get comprehensive statistics
stats = alert_manager.get_alert_statistics()
print(f"Total alerts by status: {stats['by_status']}")
print(f"Alerts by severity: {stats['by_severity']}")
print(f"Average resolution time: {stats['avg_resolution_days']} days")
# Get alert trends
trends = alert_manager.get_alert_trends(days=30)
print(f"Daily alert counts: {trends['daily']}")
print(f"Resolution time trends: {trends['resolution_time']}")
# Get source statistics
source_stats = alert_manager.get_source_statistics()
print(f"Statistics by source: {source_stats}")
# Get key performance metrics
metrics = alert_manager.get_alert_metrics(time_period='24h')
print(f"Total alerts in last 24h: {metrics['total_alerts']}")
print(f"Resolution rate: {metrics['resolution_rate']}%")
print(f"Critical alerts percentage: {metrics['critical_percentage']}%")
# Bulk operations
alerts = [
{
'title': 'Alert 1',
'description': 'Description 1',
'severity': 'warning'
},
{
'title': 'Alert 2',
'description': 'Description 2',
'severity': 'critical'
}
]
alert_manager.bulk_insert(alerts)
# Search alerts
search_results = alert_manager.search_records(
search_term='disk',
search_columns=['title', 'description']
)
Configuration
AlertManager requires a configuration file to be provided by the application that uses it. The library includes a default configuration template that you can use as a starting point.
Configuration File Location
The configuration file should be placed in your application's configuration directory. By default, AlertManager will look for:
config.yamlorconfig.yml
in the current working directory. You can also specify a custom path when initializing AlertManager:
alert_manager = AlertManager(config_path="/path/to/your/config.yaml")
Configuration Template
Here's an example configuration file (config.yaml):
database:
# Path to SQLite database file (use ":memory:" for in-memory database)
path: alertmanager.sql
# Directory containing database migrations
migrations_dir: migrations
# Connection pool settings
pool_size: 5
max_overflow: 10
# Enable SQL query logging (for debugging)
echo: false
logging:
# Enable or disable logging
enabled: true
# Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
level: INFO
# Log message format
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
# Log file path
file: alertmanager.log
alerts:
# Number of days to keep alerts before automatic deletion
retention_days: 30
# Default severity for new alerts if not specified
default_severity: info
# Default source for new alerts if not specified
default_source: system
# Maximum number of alerts to return in a single query
max_alerts_per_page: 100
# Page size for pagination
page_size: 20
# Default type for new alerts if not specified
default_type: system
Configuration Options
| Section | Option | Description | Default |
|---|---|---|---|
| database | path | Path to SQLite database file | alertmanager.sql |
| database | migrations_dir | Directory containing migrations | migrations |
| database | pool_size | Connection pool size | 5 |
| database | max_overflow | Maximum overflow connections | 10 |
| database | echo | Enable SQL query logging | false |
| logging | enabled | Enable or disable logging | true |
| logging | level | Logging level | INFO |
| logging | format | Log message format | '%(asctime)s - %(name)s - %(levelname)s - %(message)s' |
| logging | file | Log file path | alertmanager.log |
| alerts | retention_days | Days to keep alerts | 30 |
| alerts | default_severity | Default alert severity | info |
| alerts | default_source | Default alert source | system |
| alerts | max_alerts_per_page | Max alerts per query | 100 |
| alerts | page_size | Page size for pagination | 20 |
| alerts | default_type | Default alert type | system |
API Reference
AlertManager
Core Methods
create_alert(title, description, severity=None): Create a new alertget_alerts(status=None, limit=None, offset=0): Get alerts with optional filteringacknowledge_alert(alert_id, acknowledged_by): Acknowledge an alertresolve_alert(alert_id, resolved_by): Resolve an alertget_active_alerts_count(): Get count of active alerts by severitydelete_old_alerts(days=None): Delete alerts older than specified daysquery_alerts(columns=None, filters=None, order_by=None, limit=None, offset=None): Generic query functionbulk_insert(records, auto_timestamps=True): Insert multiple alertssearch_records(search_term, search_columns): Search alerts across multiple columnsget_latest_records(limit=10, date_column='created_at_evie'): Get most recent alerts
Statistical Methods
get_alert_statistics(): Get comprehensive statistics about alertsget_alert_trends(days=30): Get alert trends over timeget_source_statistics(): Get statistics about alert sourcesget_alert_metrics(time_period='24h'): Get key performance metrics for alerts
Development
Running Tests
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
python -m pytest tests/ -v
Building
# Build the package
python setup.py build
# Build and upload to PyPI
./build_and_upload.sh
License
MIT License
Metadata
Release files for evolvishub-alertmanager 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| evolvishub_alertmanager-0.2.0.tar.gz | 17.5 kB | Without provenance | Details for evolvishub_alertmanager-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| evolvishub_alertmanager-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for evolvishub_alertmanager-0.2.0-py3-none-any.whl |
Total release size: 34.0 kB
Release files / evolvishub_alertmanager-0.2.0.tar.gz
| Download URL | evolvishub_alertmanager-0.2.0.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70a61a2a561f166c771cb18679a9e95000fc877eace32cf7b746ef2de6c3660f
|
|
BLAKE2b-256 checksum How to use checksums |
6d11a11708a1e041afaf7403a9ff54938017f3e0e1f69980dba4bf76f8806df6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Release files / evolvishub_alertmanager-0.2.0-py3-none-any.whl
| Download URL | evolvishub_alertmanager-0.2.0-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be2aaf03ddd6f3e0d5d3bb69b6af6846055fa38af64e55d29cc2bd10bb63d3e8
|
|
BLAKE2b-256 checksum How to use checksums |
77ca0e796a68c9fa1d9987b20221e0a2ac5c8c0a374ec389076b7c3ef95ddf4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Security for evolvishub-alertmanager 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.