Improve timestamp handling and event navigation
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import httpx
|
||||
|
||||
from ...redaction import redact
|
||||
from ...timeutil import payload_with_display_times
|
||||
from .base import DeliveryResult
|
||||
from .http import classify_response
|
||||
|
||||
@@ -10,11 +11,13 @@ from .http import classify_response
|
||||
class AlertmanagerNotifier:
|
||||
name = "alertmanager"
|
||||
|
||||
def __init__(self, client: httpx.AsyncClient, url: str) -> None:
|
||||
def __init__(self, client: httpx.AsyncClient, url: str, time_zone: str) -> None:
|
||||
self._client = client
|
||||
self._url = url.rstrip("/")
|
||||
self._time_zone = time_zone
|
||||
|
||||
async def deliver(self, event_type: str, payload: dict) -> DeliveryResult:
|
||||
display_payload = payload_with_display_times(payload, self._time_zone)
|
||||
labels = {
|
||||
"alertname": "monlet_incident",
|
||||
"agent_id": str(payload.get("agent_id", "")),
|
||||
@@ -25,7 +28,11 @@ class AlertmanagerNotifier:
|
||||
"severity": str(payload.get("severity", "unknown")),
|
||||
"status": str(payload.get("status", "")),
|
||||
"summary": redact(payload.get("summary") or "") or "",
|
||||
"time_zone": display_payload["time_zone"],
|
||||
}
|
||||
for key in ("observed_at_display", "opened_at_display", "resolved_at_display"):
|
||||
if display_payload.get(key):
|
||||
annotations[key.removesuffix("_display")] = display_payload[key]
|
||||
if payload.get("output"):
|
||||
annotations["output"] = (redact(payload["output"]) or "")[:1024]
|
||||
alert = {
|
||||
|
||||
Reference in New Issue
Block a user