Installation
pip install ckanext-event-audit
Mit XLSX Export (optional)
pip install ckanext-event-audit[xlsx]
Configuration
ckan.plugins = … event_audit …
DB Migration
ckan db upgrade -p event_audit
Repository Konfiguration:
Active Repository (default: redis)
ckanext.event_audit.active_repo = redis # oder: basic, cloudwatch, custom
Verfügbare Repos einschränken (optional)
ckanext.event_audit.restrict_available_repos = redis basic
CloudWatch Configuration (bei cloudwatch repo):
ckanext.event_audit.cloudwatch.access_key = YOUR_ACCESS_KEY
ckanext.event_audit.cloudwatch.secret_key = YOUR_SECRET_KEY
ckanext.event_audit.cloudwatch.region = us-east-1
ckanext.event_audit.cloudwatch.log_group = /ckan/event-audit
ckanext.event_audit.cloudwatch.log_stream = event-audit-stream
Event Filtering:
Ignorierte Categories (Komma-separiert)
ckanext.event_audit.ignore.categories = test,debug
Ignorierte Actions (default: resource_view_list, user_show, etc.)
ckanext.event_audit.ignore.actions = package_search,package_show
Ignorierte Models (default: Option)
ckanext.event_audit.ignore.models = User,Package
Nur spezifische Models tracken (hat Priorität über ignore)
ckanext.event_audit.track.models = Package,Resource,User
Admin Panel:
Admin-Panel aktivieren (default: false)
ckanext.event_audit.enable_admin_panel = true
Performance:
Payload/Result Storage deaktivieren (weniger Speicher)
ckanext.event_audit.store_payload_and_result = false
Model Tracking deaktivieren
ckanext.event_audit.track_models = false
CLI Nutzung:
Export Events to CSV
ckan event-audit export –format=csv –output=/tmp/audit.csv
Export mit Datumsfilter
ckan event-audit export –format=json –start-date=2024-01-01 –end-date=2024-12-31
Export to XLSX (requires openpyxl)
ckan event-audit export –format=xlsx –output=audit.xlsx
Clear all events (VORSICHT!)
ckan event-audit clear –confirm
API Usage:
Events abrufen
events = tk.get_action(‘event_audit_get_events’)(
context,
{
‘category’: ‘package’,
‘user_id’: ‘user-123’,
‘limit’: 100,
‘offset’: 0
}
)
Event manuell erstellen
tk.get_action(‘event_audit_create_event’)(
context,
{
‘category’: ‘custom’,
‘action’: ‘my_custom_action’,
‘actor’: tk.current_user.id,
‘payload’: {‘key’: ‘value’},
‘result’: {‘status’: ‘success’}
}
)
Custom Repository Implementation:
from ckanext.event_audit.repositories import AbstractRepository
class MyCustomRepo(AbstractRepository):
def write_event(self, event_dict):
# Custom storage logic
pass
def read_events(self, filters):
# Custom retrieval logic
return []
Registrierung in plugin.py
from ckanext.event_audit.repositories import register_repository
register_repository(‘mycustom’, MyCustomRepo)