Dynamic Email Subject in Alert Manager

45 views
Skip to first unread message

Bibin John

unread,
Mar 7, 2020, 2:49:51 PM3/7/20
to Prometheus Users
I have few alerts configured in promertheus/alertmanager. I want to dynamically change email subject based on group name. how is it possible? lets say below is one of the entry.
so in below case, email subject should be alert name or suject label value. is this possible?



- alert: OfflinePartitionAlerts
    expr: kafka_controller_kafkacontroller_offlinepartitionscount{job=~"prod_.*"}>0
    for: 2m
    labels:
      group: OfflinePartition
      environment: Production
      subject: OfflinePartitionAlerts
    annotations:
      Environment: 'Production'
      Cluster: '{{ $labels.job }}'
      Node: '{{ $labels.node }}'
      Summary: 'Offline partitions in cluster'
      OfflinePartitionCount : '{{ $value }} '



Thanks
Bibin John



Christian Hoffmann

unread,
Mar 8, 2020, 4:29:16 PM3/8/20
to Bibin John, Prometheus Users
Hi,

(sorry, just found this mail after I replied to your other mail)

On 3/7/20 8:49 PM, Bibin John wrote:
> I have few alerts configured in promertheus/alertmanager. I want to
> dynamically change email subject based on group name. how is it
> possible? lets say below is one of the entry.
> so in below case, email subject should be alert name or suject label
> value. is this possible?
Yes, this should be possible.

First, you can set the email options such as subject or body
per-receiver, which already gives you some flexibility.
Second, the string is templatable -- meaning you can reference a
variable (e.g. a label), which may already be what you want.
You could even work with conditionals there.

This shows the default template for the mail subject:
https://github.com/prometheus/alertmanager/blob/master/template/default.tmpl#L84
https://github.com/prometheus/alertmanager/blob/master/template/default.tmpl#L4

You can find more details about the available fields here:
https://prometheus.io/docs/alerting/notifications/

This shows the configuration:
https://prometheus.io/docs/alerting/configuration/#email_config

And here are some more examples:
https://prometheus.io/docs/alerting/notification_examples/

Hope this helps,
Christian
Reply all
Reply to author
Forward
0 new messages