release: v1.9.0 — IRM-алерты отдельно от инцидентов
- Alembic 005: таблицы irm_alerts и incident_alert_links - Модуль alerts: API/UI, Ack/Resolve, привязка к инциденту через alert_ids - Вебхук Grafana: одна транзакция ingress + irm_alerts; разбор payload в grafana_payload - По умолчанию инцидент из вебхука не создаётся (AUTO_INCIDENT_FROM_ALERT) - Документация IRM_GRAFANA_PARITY.md, обновления IRM.md и CHANGELOG Made-with: Cursor
This commit is contained in:
@ -29,8 +29,41 @@ def test_escalations_api_list_no_db(client: TestClient) -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_incident_inserted_on_alert_received() -> None:
|
||||
"""При пуле БД подписка создаёт инцидент (INSERT)."""
|
||||
async def test_incident_not_created_from_alert_by_default() -> None:
|
||||
"""По умолчанию AUTO_INCIDENT_FROM_ALERT выкл — инцидент из вебхука не создаётся."""
|
||||
calls: list = []
|
||||
|
||||
async def fake_execute(_query, *args):
|
||||
calls.append(args)
|
||||
return "INSERT 0 1"
|
||||
|
||||
mock_conn = AsyncMock()
|
||||
mock_conn.execute = fake_execute
|
||||
mock_cm = AsyncMock()
|
||||
mock_cm.__aenter__ = AsyncMock(return_value=mock_conn)
|
||||
mock_cm.__aexit__ = AsyncMock(return_value=None)
|
||||
mock_pool = MagicMock()
|
||||
mock_pool.acquire = MagicMock(return_value=mock_cm)
|
||||
|
||||
from onguard24.domain.events import InMemoryEventBus
|
||||
from onguard24.modules import incidents as inc_mod
|
||||
|
||||
bus = InMemoryEventBus()
|
||||
inc_mod.register_events(bus, mock_pool)
|
||||
|
||||
uid = uuid4()
|
||||
ev = AlertReceived(
|
||||
alert=Alert(source="grafana", title="CPU high", severity=Severity.WARNING),
|
||||
raw_payload_ref=uid,
|
||||
)
|
||||
await bus.publish(ev)
|
||||
assert calls == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_incident_inserted_on_alert_when_auto_enabled(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""При AUTO_INCIDENT_FROM_ALERT=1 подписка снова создаёт инцидент (legacy)."""
|
||||
monkeypatch.setenv("AUTO_INCIDENT_FROM_ALERT", "1")
|
||||
inserted: dict = {}
|
||||
|
||||
async def fake_execute(_query, *args):
|
||||
|
||||
Reference in New Issue
Block a user