Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
n-benchoubane opened this issue Jul 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@n-benchoubane
Copy link

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 }}

@n-benchoubane n-benchoubane added the enhancement New feature or request label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant