Skip to content

Add Support for Customizable Email Alert Templates in Alertmanager Integration #3980

@n-benchoubane

Description

@n-benchoubane

What problem would you like to solve? Please describe:
The current implementation of the email alert template for Prometheus AlertManager is hardcoded and does not render the labels properly for email. Because webhook for the Prometheus Integration notifier sends all metadata in the request body, this needs to be supported on goalert to template the email body.

Describe the solution you'd like:
Add a way to support a customizable template for email alerts. This would allow users to define their own templates that render labels and other information correctly.

Describe alternatives you've considered:
One alternative is to improve the existing hardcoded template to ensure it renders correctly. However, this approach does not offer the flexibility that customizable templates provide.

Additional context:
The current code snippet for the email alert template is as follows:

if b.ExternalURL != "" {
	fmt.Fprintf(&s, "[Prometheus Alertmanager UI](%s)\n\n", b.ExternalURL)
}
if b.CommonAnnotations.Details != "" {
	s.WriteString(b.CommonAnnotations.Details + "\n\n")
} else {
	for _, a := range b.Alerts {
		s.WriteString(a.Details() + "\n\n")
	}
}
if payload != "" {
	fmt.Fprintf(&s, "## Payload\n\n```json\n%s\n```\n", payload)
}
return s.String()

We can envision to have something similar to email_config that is defined in AlertManager

{ define "custom_mail_subject" }}Alert on {{ range .Alerts.Firing }}{{ .Labels.instance }} {{ end }}{{ end }}
{{ define "custom_mail_html" }}
<html>
<head>
<title>Alert!</title>
</head>
<body>
{{ range .Alerts.Firing }}

<p>{{ .Labels.alertname }} on {{ .Labels.instance }}<br/>
{{ if ne .Annotations.summary "" }}{{ .Annotations.summary }}{{ end }}</p>

<p>Details:</p>

<p>
{{ range .Annotations.SortedPairs }}
  {{ .Name }} = {{ .Value }}<br/>
{{ end }}
</p>

<p>
{{ range .Labels.SortedPairs }}
  {{ .Name }} = {{ .Value }}<br/>
{{ end }}
</p>

{{ end }}

</body></html>
{{ end }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requeststaleThis is inactive

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions