Inserting a label value into e-mail subject

1,484 views
Skip to first unread message

sutirt...@gmail.com

unread,
Aug 29, 2018, 11:10:27 PM8/29/18
to Prometheus Users
I want to extract say, the value of an alert label and put it in the Subject of my mail.

a simpler form of the current setup i have is:

rules.yml   (Prometheus)


groups
:

- name: example

  rules:

  # Alert for any node down for 20s

  - alert: InstanceDown

    expr: up == 0

    for: 20s

    labels:

      severity: 'critical'

      target: 'targetNotifierSystem'


and the corresponding alertmanager settings.yml


...
receivers:
- name: 'target-mail'
  email_configs:
  - to: 'target@email'
    send_resolved: true
    headers:
      subject: '[{{ .Labels.severity }}] Test mail subject'
    html: null
...
 

My aim is to replace .Labels.severity with 'critical'. This setup throws some parsing errors. 
level=error ts=2018-08-30T02:02:21.178883979Z caller=notify.go:332 component=dispatcher msg="Error on notify" err="cancelling notify retry for \"email\" due to unrecoverable error: executing \"Subject\" header template: template: :1:11: executing \"\" at <.Labels.severity>: can't evaluate field Labels in type *template.Data"

using .CommonLabels.severity inserts nothing.

Brian Brazil

unread,
Aug 30, 2018, 2:24:10 AM8/30/18
to sutirt...@gmail.com, Prometheus Users
On 30 August 2018 at 04:10, <sutirt...@gmail.com> wrote:
I want to extract say, the value of an alert label and put it in the Subject of my mail.

a simpler form of the current setup i have is:

rules.yml   (Prometheus)


groups
:

- name: example

  rules:

  # Alert for any node down for 20s

  - alert: InstanceDown

    expr: up == 0

    for: 20s

    labels:

      severity: 'critical'

      target: 'targetNotifierSystem'


and the corresponding alertmanager settings.yml


...
receivers:
- name: 'target-mail'
  email_configs:
  - to: 'target@email'
    send_resolved: true
    headers:
      subject: '[{{ .Labels.severity }}] Test mail subject'

A receiver gets a list of alerts, not just one, each of which has their own severity. In a typical alert routing setup all of those will have the same severity so you can use .CommonLabels.severity to get that.

Brian

 
    html: null
...
 

My aim is to replace .Labels.severity with 'critical'. This setup throws some parsing errors. 
level=error ts=2018-08-30T02:02:21.178883979Z caller=notify.go:332 component=dispatcher msg="Error on notify" err="cancelling notify retry for \"email\" due to unrecoverable error: executing \"Subject\" header template: template: :1:11: executing \"\" at <.Labels.severity>: can't evaluate field Labels in type *template.Data"

using .CommonLabels.severity inserts nothing.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/c13c5d29-ccd5-434d-aa85-40941af49d3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Bibin John

unread,
Mar 8, 2020, 12:57:24 AM3/8/20
to Prometheus Users
did you get solution for this? if yes, what was the solution?

Christian Hoffmann

unread,
Mar 8, 2020, 4:23:16 PM3/8/20
to Bibin John, Prometheus Users
On 3/8/20 6:57 AM, Bibin John wrote:
> did you get solution for this? if yes, what was the solution?
Brian had replied to the initial mail.
Do you have any issues with implementing this?

If so, try describing your issue with some more details so that someone
can help.

Kind regards,
Christian
Reply all
Reply to author
Forward
0 new messages