Skip to content

feat: Add labels template and improve error diagnostics - #22

Open
day1118 wants to merge 3 commits into
alexbakker:masterfrom
day1118:labels-template
Open

feat: Add labels template and improve error diagnostics#22
day1118 wants to merge 3 commits into
alexbakker:masterfrom
day1118:labels-template

Conversation

@day1118

@day1118 day1118 commented Feb 9, 2026

Copy link
Copy Markdown

Add an optional labels template 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.

templates:
  labels: |
    {{range $key, $value := .}}{{$key}} = {{$value}}, {{end}}

To filter or transform labels:

templates:
  labels: |
    {{range $key, $value := .}}{{if ne $key "internal"}}{{ capitalize $value }}, {{end}}{{end}}

day1118 and others added 2 commits May 14, 2026 14:00
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.
@day1118
day1118 force-pushed the labels-template branch from c0eb804 to 63ba3ee Compare May 14, 2026 04:03
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.
Comment thread internal/config/config.go
allowedTopicRegex = regexp.MustCompile(`^[-_A-Za-z0-9]{1,64}$`)

// TemplateFuncs contains custom functions available in templates.
TemplateFuncs = template.FuncMap{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use sprig instatt of develop the functio map on this own, see #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants