Skip to content

Commit 95dfa66

Browse files
authored
Update guide for Turbot > Notifications > Webhook #349 (#363)
1 parent d9f28e2 commit 95dfa66

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

docs/guides/using-guardrails/notifications/filter-rules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The policy contains an array of `rule-sets`. Each `rule-set` consists of 1 or m
1313

1414
- Slack webhook
1515
- Microsoft Teams webhook
16+
- Custom Webhook
1617
- Email Addresses
1718
- [Profiles](/guardrails/docs/guides/using-guardrails/notifications#routing-to-profiles)
1819

docs/guides/using-guardrails/notifications/index.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Guardrails currently supports the following delivery channels for notifications:
1919

2020
2. **Slack notifications** are sent via standard webhooks. For documentation on configuring webhooks for slack see: `https://api.slack.com/messaging/webhooks`
2121
3. **Microsoft Teams notifications** are also sent via webhooks. For Teams documentation see: https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet
22-
4. **Event Streams** can be created and consumed using the [Guardrails Firehose](/guardrails/docs/guides/configuring-guardrails/firehose) feature.
22+
4. **Custom webhook notifications** can be sent to any HTTPS endpoint that accepts POST requests with JSON payloads. This allows integration with custom systems, ticketing platforms, monitoring tools, or any service that provides webhook endpoints. Webhooks support optional authorization headers for secure delivery. Configure webhook delivery using the [Turbot > Notifications > Webhook](https://hub.guardrails.turbot.com/mods/turbot/policies/turbot/notificationsWebhook) policy and optional authentication with the [Turbot > Notifications > Webhook > Authorization Header](https://hub.guardrails.turbot.com/mods/turbot/policies/turbot/notificationsWebhookAuthorizationHeader) policy.
23+
5. **Event Streams** can be created and consumed using the [Guardrails Firehose](/guardrails/docs/guides/configuring-guardrails/firehose) feature.
2324

2425

2526
### Routing to Profiles
@@ -80,12 +81,14 @@ Here is a base example of two common types of rules:
8081
- d.schrute@dmi.com
8182
slackWebhookUrl: "https://hooks.slack.com/services/T02GC4A7C/BUDS3GB05P/iI27FCQjgiI27FCQ"
8283
msTeamsWebhookUrl: "https://dundermifflin.webhook.office.com/webhookb2/25bbe4f5-9d8e-485c-9fd/IncomingWebhook/534528d9c02/944a8e14"
84+
webhookUrl: "https://api.dundermifflin.com/guardrails/notifications"
8385
8486
- rules: "NOTIFY $.actionType.parent:'#/resource/types/securityGroup'"
8587
emails:
8688
- d.schrute@dmi.com
8789
slackWebhookUrl: "https://hooks.slack.com/services/T02GC4A7C/BUDS3GB05P/iI27FCQjgiI27FCQ"
8890
msTeamsWebhookUrl: "https://dundermifflin.webhook.office.com/webhookb2/25bbe4f5-9d8e-485c-9fd/IncomingWebhook/534528d9c02/944a8e14"
91+
webhookUrl: "https://monitoring.dundermifflin.com/alerts/turbot"
8992
```
9093

9194
The first rule sends a notification to an email every time a control changes from `OK` state to `Alarm` state, and the second rule sends a notification when Guardrails takes an enforcement action against a security group rule (the parent of a security group rule is the `securityGroup`)
@@ -106,7 +109,7 @@ Guardrails keeps track of the number of notifications being sent to individual r
106109

107110
## Templates
108111

109-
Templates control the format of notifications. Separate templates exist for each delivery channel (Email, Slack, Teams) and for each delivery type (single and batch). The default templates for each channel integrate [Guardrails Quick Actions](guides/quick-actions) and serve as a great jumping off point for your own customization. The default templates can be overridden by setting the following policies:
112+
Templates control the format of notifications. Separate templates exist for each delivery channel (Email, Slack, Teams, Webhook) and for each delivery type (single and batch). The default templates for each channel integrate [Guardrails Quick Actions](guides/quick-actions) and serve as a great jumping off point for your own customization. The default templates can be overridden by setting the following policies:
110113

111114
```
112115
Turbot > Notifications > Email > Action Template > Subject
@@ -130,8 +133,13 @@ Turbot > Notifications > Microsoft Teams > Action Template > Batch Body
130133
131134
Turbot > Notifications > Microsoft Teams > Control Template > Body
132135
Turbot > Notifications > Microsoft Teams > Control Template > Batch Body
136+
137+
Turbot > Notifications > Webhook > Action Template > Body
138+
Turbot > Notifications > Webhook > Control Template > Body
133139
```
134140

141+
**Note**: Webhook notifications do not support batch templates and only send individual notifications.
142+
135143
Templates are created using graphql for the query and [Nunjucks](https://mozilla.github.io/nunjucks/templating.html) for the templating language (very similar to calculated policies).
136144

137145
For examples and documentation on how to customize templates please see [Templates →](guides/notifications/templates)
@@ -156,6 +164,20 @@ Turbot > Notifications > Email > SMTP Username (if no username is needed s
156164
Turbot > Notifications > Email > SMTP Password (if no password is needed set to `null`)
157165
```
158166

167+
### Webhook Setup
168+
169+
For webhook notifications, configure the following policies:
170+
171+
```
172+
Turbot > Notifications > Webhook > Authorization Header - Optional authorization header for secure webhook delivery (e.g., `Token your-secret-token` or `Bearer your-api-key`)
173+
Turbot > Notifications > Webhook > Action Template > Body - Customize the JSON payload format for action notifications
174+
Turbot > Notifications > Webhook > Control Template > Body - Customize the JSON payload format for control notifications
175+
```
176+
177+
**Template Configuration**: The sample [Webhook templates](guides/notifications/templates) outputs all available notification data as JSON. This provides the complete data structure that you can then customize by selecting specific fields and formatting them according to your system's requirements. You can also copy Slack templates as a starting point and modify the JSON structure.
178+
179+
Webhook notifications are sent as HTTPS POST requests with JSON payloads to the URLs specified in your notification rules.
180+
159181
Once notifications are enabled and email is configured we suggest triggering one of your filter rules and ensuring that message delivery works.
160182

161183
**Next**: [See how to configure filter rule-sets →](guides/notifications/filter-rules)

docs/guides/using-guardrails/notifications/templates.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Turbot > Notifications > Microsoft Teams > Action Template > Batch Body
4444
4545
Turbot > Notifications > Microsoft Teams > Control Template > Body
4646
Turbot > Notifications > Microsoft Teams > Control Template > Batch Body
47+
48+
Turbot > Notifications > Webhook > Action Template > Body
49+
Turbot > Notifications > Webhook > Control Template > Body
4750
```
4851

4952
## Template Definition
@@ -340,4 +343,100 @@ query notificationDetails($filter: [String!], $resourceId: ID!) {
340343
{%- endif %}
341344
]
342345
}
346+
```
347+
348+
## Example Custom Webhook Control Template
349+
350+
```nunjucks
351+
{% input %}
352+
query controlGet($id: ID!, $resourceId: ID!) {
353+
workspaceUrl: policyValue(
354+
uri: "tmod:@turbot/turbot#/policy/types/workspaceUrl"
355+
resourceId: $resourceId
356+
) {
357+
value
358+
}
359+
oldControl: control(id: $id) {
360+
actor {
361+
identity {
362+
picture
363+
turbot {
364+
title
365+
id
366+
}
367+
}
368+
}
369+
state
370+
reason
371+
details
372+
type {
373+
trunk {
374+
title
375+
}
376+
}
377+
turbot {
378+
createTimestamp
379+
updateTimestamp
380+
id
381+
}
382+
resource {
383+
metadata
384+
turbot {
385+
id
386+
title
387+
}
388+
trunk {
389+
title
390+
}
391+
type {
392+
title
393+
}
394+
}
395+
}
396+
}
397+
398+
{% endinput %}
399+
400+
{{ $ | dump }}
401+
```
402+
403+
## Example Custom Webhook Action Template
404+
405+
```nunjucks
406+
{% input %}
407+
query controlGet($id: ID!, $resourceId: ID!, $notificationId: ID!) {
408+
workspaceUrl: policyValue(
409+
uri: "tmod:@turbot/turbot#/policy/types/workspaceUrl"
410+
resourceId: $resourceId
411+
) {
412+
value
413+
}
414+
notification(id: $notificationId) {
415+
message
416+
resource {
417+
metadata
418+
turbot{
419+
id
420+
}
421+
trunk {
422+
title
423+
}
424+
}
425+
}
426+
control(id: $id) {
427+
turbot{
428+
id
429+
}
430+
type {
431+
trunk {
432+
title
433+
}
434+
}
435+
}
436+
}
437+
438+
{% endinput %}
439+
440+
441+
{{ $ | dump }}
343442
```

0 commit comments

Comments
 (0)