feat(10-01): add audit event logging to config backup operations

- config_snapshot_created event after successful snapshot INSERT
- config_snapshot_skipped_duplicate event on dedup match
- config_diff_generated event after diff INSERT
- config_backup_manual_trigger event on manual trigger success
- All log_action calls wrapped in try/except for safety

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jason Staack
2026-03-12 23:44:00 -05:00
parent 50211d1853
commit 1a1ceb2cb1
4 changed files with 68 additions and 2 deletions

View File

@@ -162,6 +162,27 @@ async def generate_and_store_diff(
lines_removed,
)
try:
from app.services.audit_service import log_action
import uuid as _uuid
await log_action(
db=None,
tenant_id=_uuid.UUID(tenant_id),
user_id=None,
action="config_diff_generated",
resource_type="config_diff",
resource_id=str(diff_id),
device_id=_uuid.UUID(device_id),
details={
"old_snapshot_id": str(old_snapshot_id),
"new_snapshot_id": new_snapshot_id,
"lines_added": lines_added,
"lines_removed": lines_removed,
},
)
except Exception:
pass
# 11. Parse structured changes (best-effort)
try:
changes = parse_diff_changes(diff_text)