feat: Add alert endpoints to alert_processor service for dashboard

Implemented missing alert endpoints that the dashboard requires for
health status and action queue functionality.

Alert Processor Service Changes:
- Created alerts_repository.py:
  * get_alerts() - Filter alerts by severity/status/resolved with pagination
  * get_alerts_summary() - Count alerts by severity and status
  * get_alert_by_id() - Get specific alert

- Created alerts.py API endpoints:
  * GET /api/v1/tenants/{tenant_id}/alerts/summary - Alert counts
  * GET /api/v1/tenants/{tenant_id}/alerts - Filtered alert list
  * GET /api/v1/tenants/{tenant_id}/alerts/{alert_id} - Single alert

- Severity mapping: "critical" (dashboard) maps to "urgent" (alert_processor)
- Status enum: active, resolved, acknowledged, ignored
- Severity enum: low, medium, high, urgent

API Server Changes:
- Registered alerts_router in api_server.py
- Exported alerts_router in __init__.py

Procurement Client Changes:
- Updated get_critical_alerts() to use /alerts path
- Updated get_alerts_summary() to use /alerts/summary path
- Added severity mapping (critical → urgent)
- Added documentation about gateway routing

This fixes the 404 errors for alert endpoints in the dashboard.
This commit is contained in:
Claude
2025-11-07 22:16:16 +00:00
parent 6cd4ef0f56
commit 41d292913a
5 changed files with 413 additions and 6 deletions

View File

@@ -611,6 +611,8 @@ class ProcurementServiceClient(BaseServiceClient):
"""
Get critical alerts for dashboard
Note: "critical" maps to "urgent" severity in alert_processor service
Args:
tenant_id: Tenant ID
limit: Maximum number of alerts to return
@@ -619,10 +621,12 @@ class ProcurementServiceClient(BaseServiceClient):
Dict with {"alerts": [...], "total": n}
"""
try:
# Gateway routes /tenants/{tenant_id}/alerts/... to alert_processor service
# "critical" in dashboard = "urgent" severity in alert_processor
return await self.get(
"/procurement/alert-processor/alerts",
"/alerts",
tenant_id=tenant_id,
params={"severity": "critical", "resolved": False, "limit": limit}
params={"severity": "urgent", "resolved": False, "limit": limit}
)
except Exception as e:
logger.error("Error fetching critical alerts", error=str(e), tenant_id=tenant_id)
@@ -639,11 +643,12 @@ class ProcurementServiceClient(BaseServiceClient):
tenant_id: Tenant ID
Returns:
Dict with counts by severity
Dict with counts by severity (critical_count maps to urgent severity)
"""
try:
# Gateway routes /tenants/{tenant_id}/alerts/... to alert_processor service
return await self.get(
"/procurement/alert-processor/alerts/summary",
"/alerts/summary",
tenant_id=tenant_id
)
except Exception as e: