27 lines
840 B
Python
27 lines
840 B
Python
|
|
"""Парсинг полей из тела вебхука Grafana."""
|
||
|
|
|
||
|
|
from onguard24.ingress.grafana_payload import extract_alert_row_from_grafana_body
|
||
|
|
|
||
|
|
|
||
|
|
def test_extract_title_and_severity_from_unified() -> None:
|
||
|
|
body = {
|
||
|
|
"title": "RuleName",
|
||
|
|
"alerts": [
|
||
|
|
{
|
||
|
|
"labels": {"severity": "critical", "alertname": "X"},
|
||
|
|
"fingerprint": "abc",
|
||
|
|
}
|
||
|
|
],
|
||
|
|
}
|
||
|
|
title, sev, labels, fp = extract_alert_row_from_grafana_body(body)
|
||
|
|
assert title == "RuleName"
|
||
|
|
assert sev == "critical"
|
||
|
|
assert labels.get("alertname") == "X"
|
||
|
|
assert fp == "abc"
|
||
|
|
|
||
|
|
|
||
|
|
def test_extract_empty_title_uses_alertname() -> None:
|
||
|
|
body = {"alerts": [{"labels": {"alertname": "HostDown"}}]}
|
||
|
|
title, _, _, _ = extract_alert_row_from_grafana_body(body)
|
||
|
|
assert title == "HostDown"
|