oncall-engine/engine/apps/webhooks/presets/simple.py
Matias Bordese e93858e136
Add manual trigger support for webhooks (#4934)
Related to https://github.com/grafana/oncall/issues/4748

- Added support for additional filters when getting webhooks:
- `GET
/api/plugins/grafana-oncall-app/resources/webhooks/?integration=CALBFV7RRDH93`
  (filter webhooks that are enabled for the specified integration)
- `GET
/api/plugins/grafana-oncall-app/resources/webhooks/?trigger_type=0`
  (filter webhooks with the given trigger type)
- Allow triggering a Manual webhook using an alert group as context:
`POST /api/plugins/grafana-oncall-app/resources/webhooks/<webhook public
ID>/trigger_manual`
Example payload: `{"alert_group": "I4A4I1UPSA7IC"}`
(will return a 200 OK on success)

---------

Co-authored-by: Rares Mardare <rares.mardare@grafana.com>
2024-09-09 12:17:23 +00:00

37 lines
1.2 KiB
Python

import typing
from apps.webhooks.models import Webhook
from apps.webhooks.presets.preset import WebhookPreset, WebhookPresetMetadata
class SimpleWebhookPreset(WebhookPreset):
def _metadata(self) -> WebhookPresetMetadata:
return WebhookPresetMetadata(
id="simple_webhook",
name="Simple",
logo="webhook",
description="A simple webhook which sends the alert group data to a given URL. Triggered as an escalation step.",
controlled_fields=[
"trigger_type",
"http_method",
"integration_filter",
"headers",
"username",
"password",
"authorization_header",
"trigger_template",
"forward_all",
"data",
],
)
def override_parameters_before_save(self, webhook: Webhook):
webhook.http_method = "POST"
webhook.trigger_type = Webhook.TRIGGER_MANUAL
webhook.forward_all = True
def override_parameters_at_runtime(self, webhook: Webhook):
pass
def get_masked_headers(self) -> typing.List[str]:
return []