alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Fix resolved header in email template

Open nileger opened this issue 3 years ago • 2 comments

Background

We use a custom email template based on alertmanager/template/email.tmpl.

Problem

The email template for resolved messages currently has a styling issue. Due to an extra </td>, the green heading is only shown in the top right corner, instead of covering the full width.

image

Solution

Removing the extra </td> solves the issue.

image

nileger avatar Apr 05 '22 10:04 nileger

Can anyone help with the DCO check, please?

nileger avatar Apr 05 '22 11:04 nileger

template/email.tmpl gets generated from template/email.html via the template/inline-css.js script which uses juice under the hood to inline the CSS properies into the style attributes.

IIUC juice is confused by this part and adds the extra </td> https://github.com/prometheus/alertmanager/blob/dcc92eda2ecbb96948c1e864338bfbf32ce8885b/template/email.html#L326-L334

One way to fix it would be to duplicate the range loop like this:

 {{ if gt (len .Alerts.Firing) 0 }} 
 <td class="alert alert-warning"> 
   {{ .Alerts | len }} alert{{ if gt (len .Alerts) 1 }}s{{ end }} for {{ range .GroupLabels.SortedPairs }} 
     {{ .Name }}={{ .Value }}  
   {{ end }} 
 </td>
 {{ else }} 
 <td class="alert alert-good"> 
   {{ .Alerts | len }} alert{{ if gt (len .Alerts) 1 }}s{{ end }} for {{ range .GroupLabels.SortedPairs }} 
     {{ .Name }}={{ .Value }}  
   {{ end }} 
 </td>
 {{ end }} 

simonpasquier avatar May 04 '22 09:05 simonpasquier

Can this be merged? We are having the same problem and is annoying.

cod-r avatar Feb 27 '23 20:02 cod-r

@cod-r this should be fixed in the latest v0.25.0 thanks to #3166

simonpasquier avatar Feb 28 '23 08:02 simonpasquier