New alert system and panel de control page

This commit is contained in:
Urtzi Alfaro
2025-11-27 15:52:40 +01:00
parent 1a2f4602f3
commit e902419b6e
178 changed files with 20982 additions and 6944 deletions

View File

@@ -87,3 +87,65 @@ async def run_cleanup(
cleanup_service = DemoCleanupService(db, redis)
stats = await cleanup_service.cleanup_expired_sessions()
return stats
@router.post(
"/demo/sessions/{session_id}/seed-alerts",
response_model=dict
)
async def seed_demo_alerts(
session_id: str = Path(...),
db: AsyncSession = Depends(get_db),
redis: DemoRedisWrapper = Depends(get_redis)
):
"""Seed enriched demo alerts for a demo session (DEMO OPERATION)"""
try:
import subprocess
import os
# Get session to validate and get tenant_id
session_manager = DemoSessionManager(db, redis)
session = await session_manager.get_session(session_id)
if not session:
raise HTTPException(status_code=404, detail="Demo session not found")
# Set environment variables for seeding script
env = os.environ.copy()
env['DEMO_TENANT_ID'] = str(session.virtual_tenant_id)
# Determine script path based on environment
# In container: /app/scripts/seed_enriched_alert_demo.py
# In development: services/demo_session/scripts/seed_enriched_alert_demo.py
script_path = '/app/scripts/seed_enriched_alert_demo.py' if os.path.exists('/app/scripts') else 'services/demo_session/scripts/seed_enriched_alert_demo.py'
# Run the seeding script
result = subprocess.run(
['python3', script_path],
env=env,
capture_output=True,
text=True,
timeout=30
)
if result.returncode != 0:
logger.error("Alert seeding failed",
stdout=result.stdout,
stderr=result.stderr)
raise HTTPException(status_code=500, detail=f"Alert seeding failed: {result.stderr}")
logger.info("Demo alerts seeded successfully", session_id=session_id)
return {
"status": "success",
"session_id": session_id,
"tenant_id": str(session.virtual_tenant_id),
"alerts_seeded": 5,
"message": "Demo alerts published and will be enriched automatically"
}
except subprocess.TimeoutExpired:
raise HTTPException(status_code=504, detail="Alert seeding timeout")
except Exception as e:
logger.error("Failed to seed alerts", error=str(e), session_id=session_id)
raise HTTPException(status_code=500, detail=str(e))