Webhook Improvements - Templateable Payloads#309
Merged
JacobsonMT merged 9 commits intomainfrom Apr 11, 2025
Merged
Conversation
moustafab
approved these changes
Apr 9, 2025
Contributor
moustafab
left a comment
There was a problem hiding this comment.
Looks great! Nice work!
My only thoughts on the implementation are around further improvements in the supported functions. If we anticipate significant churn here it may be good to establish an experimental namespace which we document to allow for a bit of safer additions. I'm hesitant to support to much without clear needs and I think this approach you've taken so far is far preferable to pulling in an entire library until clear need is well documented/established.
Also, templating header values might come in handy in the future but maybe we can wait for a request from the community before adding that.
76be299 to
0e98a49
Compare
titolins
approved these changes
Apr 10, 2025
Contributor
titolins
left a comment
There was a problem hiding this comment.
weekly board maintenance ✅ 😂
great work 👏
2 tasks
- Keep original case of headers - Remove redundant tmplErr nil check but keep comment
This was referenced Apr 11, 2025
davidfrickert
pushed a commit
to davidfrickert/alerting
that referenced
this pull request
Apr 24, 2025
* Select gomplate template functions * Webhook custom payload template * Custom headers * Remove need for .Extra on ExtendedData by adding actual fields * Support empty payload * Test fix * Linting * Address review comments - Keep original case of headers - Remove redundant tmplErr nil check but keep comment * Add license info to individual files copied from gomplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces enhancements to the webhook notifier, focusing on three main areas:
Key Changes
1. Custom Payload Templates
CustomPayloadfield with:Templatefield for defining the payload structureVarsfield for providing additional template variables accessible in context via.Vars.<variable_name>2. Custom HTTP Headers
Content-Typeheader for your custom payload.Authorization,Cookie,Hostare protected3. New Template Functions
collnamespace for collection operations (Dict,Slice,Append)datanamespace for JSON operations (JSON,ToJSON,ToJSONPretty)tmplnamespace for template operations compatible with pipelines (Inline,Exec)timenamespace for time operations (Now)eJSONdecryption capability ofdata.JSONwhich reads from environment variables. That being said, none of this is insurmountable, and the plan should be to eventually incorporate the gomplate library directly and more broadly.4. Related Improvements
ExtendedDataandExtendedAlertto make sure custom payloads have access to all of the information the default webhook payload has:ExtendedAlert.OrgIdExtendedData.GroupKeyExtendedData.TruncatedAlertsRelated Requests
Issues for supporting new notifiers in Grafana are fairly common and are generally reasonable requests. However, they can come with significant burden of maintenance. Some examples:
Requests for related features are some of the most popular in Alerting:
Upstream Prometheus Alertmanager also has significant community requests, although consensus so far has been to keep the webhook notifier as-is with recommendations to set up a small web server to act as a webhook bridge:
Future Work
Custom Payload Examples
Could be as simple as writing JSON directly:
{ "alert_name": "{{ .CommonLabels.alertname }}", "status": "{{ .Status }}", "environment": "{{ .Vars.environment }}", "custom_field": "{{ .Vars.custom_field }}" }Or using new functions to help craft valid JSON:
Review Tips