v1.4.0: модули с веб-UI, правое меню, расширенные тесты
Реестр MODULE_MOUNTS: API, ui_router, фрагменты главной, EventBus. Главная и страницы модулей с правой навигацией из реестра; wrap_module_html_page. Ingress: публикация alert.received после сохранения в БД. Документация MODULES.md; pytest покрывает API, UI и навигацию. Made-with: Cursor
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Request
|
||||
from starlette.responses import Response
|
||||
|
||||
from onguard24.domain.entities import Alert, Severity
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter(tags=["ingress"])
|
||||
|
||||
@ -35,9 +38,21 @@ async def grafana_webhook(
|
||||
return Response(status_code=202)
|
||||
|
||||
async with pool.acquire() as conn:
|
||||
await conn.execute(
|
||||
"INSERT INTO ingress_events (source, body) VALUES ($1, $2::jsonb)",
|
||||
row = await conn.fetchrow(
|
||||
"INSERT INTO ingress_events (source, body) VALUES ($1, $2::jsonb) RETURNING id",
|
||||
"grafana",
|
||||
json.dumps(body),
|
||||
)
|
||||
raw_id = row["id"] if row else None
|
||||
bus = getattr(request.app.state, "event_bus", None)
|
||||
if bus and raw_id is not None:
|
||||
title = str(body.get("title") or body.get("ruleName") or "")[:500]
|
||||
alert = Alert(
|
||||
source="grafana",
|
||||
title=title,
|
||||
severity=Severity.WARNING,
|
||||
payload=body,
|
||||
received_at=datetime.now(timezone.utc),
|
||||
)
|
||||
await bus.publish_alert_received(alert, raw_payload_ref=raw_id)
|
||||
return Response(status_code=202)
|
||||
|
||||
Reference in New Issue
Block a user