feat: Add labels template and improve error diagnostics - #22
Open
day1118 wants to merge 3 commits into
Open
Conversation
day1118
force-pushed
the
labels-template
branch
from
February 9, 2026 02:12
9bdc719 to
c0eb804
Compare
Add an optional labels template field to customize how alert labels are converted to ntfy tags. When configured, the template renders alert labels and splits the output by comma to produce individual tags. If not specified, the existing default behavior (key = value format) is preserved. Include a set of template helper functions (split, join, trim, lower, upper, capitalize, contains, hasPrefix, hasSuffix, replace, printf) available in all templates. Include the ntfy response body in forwarding error messages for easier debugging of rejected requests. Fix unquoted yaml struct tag on the Headers field.
Pass the full templateContext (Alert + Payload) to the labels template,
consistent with how title, description, and headers templates are rendered.
This makes .Status, .Labels, and .Annotations available in the labels
template, enabling patterns like emoji selection based on alert status:
{{- if eq .Status "firing" -}}
{{- with index .Labels "emoji" -}}{{ . }}{{- else -}}rotating_light{{- end -}}
{{- else -}}white_check_mark{{- end -}}
Existing labels templates must update bare . range iterations to .Labels.
wrenix
reviewed
Jun 23, 2026
| allowedTopicRegex = regexp.MustCompile(`^[-_A-Za-z0-9]{1,64}$`) | ||
|
|
||
| // TemplateFuncs contains custom functions available in templates. | ||
| TemplateFuncs = template.FuncMap{ |
There was a problem hiding this comment.
Maybe we should use sprig instatt of develop the functio map on this own, see #25
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.
Add an optional
labelstemplate field to customize how alert labels are converted to ntfy tags. When not configured, the existing default behavior is preserved.Also adds template helper functions (
split,join,trim,lower,upper,capitalize,contains,hasPrefix,hasSuffix,replace,printf) available in all templates, and includes the ntfy response body in forwarding error messages for easier debugging.To filter or transform labels: