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_dict
|
||||
from ...timeutil import payload_with_display_times
|
||||
from .base import DeliveryResult
|
||||
from .http import classify_response
|
||||
|
||||
@@ -10,16 +11,22 @@ from .http import classify_response
|
||||
class WebhookNotifier:
|
||||
name = "webhook"
|
||||
|
||||
def __init__(self, client: httpx.AsyncClient, url: str, token: str = "") -> None:
|
||||
def __init__(
|
||||
self, client: httpx.AsyncClient, url: str, token: str = "", time_zone: str = "UTC"
|
||||
) -> None:
|
||||
self._client = client
|
||||
self._url = url
|
||||
self._token = token
|
||||
self._time_zone = time_zone
|
||||
|
||||
async def deliver(self, event_type: str, payload: dict) -> DeliveryResult:
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if self._token:
|
||||
headers["Authorization"] = f"Bearer {self._token}"
|
||||
body = {"event_type": event_type, "incident": redact_dict(payload)}
|
||||
body = {
|
||||
"event_type": event_type,
|
||||
"incident": redact_dict(payload_with_display_times(payload, self._time_zone)),
|
||||
}
|
||||
try:
|
||||
resp = await self._client.post(self._url, json=body, headers=headers)
|
||||
except httpx.HTTPError as exc:
|
||||
|
||||
Reference in New Issue
Block a user