Skip to content

Commit 6f385c2

Browse files
committed
initial manual changes
1 parent 5534295 commit 6f385c2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

docs/docs/guide/9-alerts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Consider configuring a "no queries submitted" alert to monitor system health. If
2424

2525
## Alert Mediums
2626

27-
Groundlight supports the following alerts via Email and Text Message (SMS), with webhook support coming soon.
27+
Groundlight supports the following alerts via Email, Text Message (SMS), and Webhooks.

src/groundlight/experimental_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from groundlight_openapi_client.model.status_enum import StatusEnum
3131
from groundlight_openapi_client.model.verb_enum import VerbEnum
3232
from groundlight_openapi_client.model.webhook_action_request import WebhookActionRequest
33+
from groundlight_openapi_client.model.payload_template_request import PayloadTemplateRequest
3334
from model import (
3435
ROI,
3536
Action,
@@ -43,6 +44,7 @@
4344
PaginatedRuleList,
4445
Rule,
4546
WebhookAction,
47+
PayloadTemplate,
4648
)
4749

4850
from groundlight.images import parse_supported_image_types
@@ -163,7 +165,7 @@ def make_action(
163165
include_image=include_image,
164166
)
165167

166-
def make_webhook_action(self, url: str, include_image: bool) -> WebhookAction:
168+
def make_webhook_action(self, url: str, include_image: bool, payload_template: Optional[str] = None) -> WebhookAction:
167169
"""
168170
Creates a WebhookAction object for use in creating alerts
169171
This function serves as a convenience method; WebhookAction objects can also be created directly.
@@ -173,10 +175,14 @@ def make_webhook_action(self, url: str, include_image: bool) -> WebhookAction:
173175
action = gl.make_webhook_action("https://example.com/webhook", include_image=True)
174176
:param url: The URL to send the webhook to
175177
:param include_image: Whether to include the triggering image in the webhook payload
178+
:param payload_template: Optional custom template for the webhook payload. The template will be rendered with
179+
the alert data. The template must be a valid Jinja2 template which produces valid JSON when rendered. If no
180+
template is provided, the default template designed for Slack will be used.
176181
"""
177182
return WebhookAction(
178183
url=str(url),
179184
include_image=include_image,
185+
payload_template=PayloadTemplate(template=payload_template),
180186
)
181187

182188
def create_alert( # pylint: disable=too-many-locals, too-many-arguments # noqa: PLR0913
@@ -266,6 +272,7 @@ def create_alert( # pylint: disable=too-many-locals, too-many-arguments # noqa
266272
WebhookActionRequest(
267273
url=str(webhook_action.url),
268274
include_image=webhook_action.include_image,
275+
payload_template=PayloadTemplateRequest(template=webhook_action.payload_template) if webhook_action.payload_template else None,
269276
)
270277
for webhook_action in webhook_actions
271278
]

0 commit comments

Comments
 (0)