prometheus / prometheus/alertmanager

Expose Alert data structure in alert fields

Open
#2,911 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
8.6k
Forks
2.5k
Avg merge
2d 6h
Merged PRs (30d)
61

Description

What did you do?
Tried to use the StartsAt field on the alert data structure in an alert notification template.

What did you expect to see?
Access to the alert data structure in the templates.

What did you see instead? Under which circumstances?
The only fields available in the alert templates are .Value, .Labels, .ExternalLabels, and .ExternalURL.

We have annotations in our alerts that link to the logs and dashboard for the particular service. I want to be able to timebox my logs and dashboard urls to the timeframe of when the alert fired in case the alert is not checked right away so that at any time these urls are clicked on for an alert, it links directly to the timeframe of when the alert occurred.

Example of what I need to be able to do:

  groups:
  - name: test-rule
    rules:
    - alert: test-alert
      annotations:
        logs_url: https://www.my-logs-url.com?starts-at={{ (index .Alerts 0).StartsAt.Format "XXX" }}

Error that I see when alert manager tries to execute this template:

can't evaluate field Alerts in type struct { Labels map[string]string; ExternalLabels map[string]string; Value float64 }

Is there any reason why .Alerts is not accessible in these templates?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the alert notification template context described in the issue and reproduce the reported .Alerts evaluation error. Trace how template data is assembled, then expose the alert data structure including StartsAt and cover the example in a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
observability-sre
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.