I am trying to customize an email template from AlertManager that uses a Go html template that prints a list of alerts using the following construct:
{{ range .Alerts.Firing }}
It is inserted into the template as follows:
func (n *Email) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
...
data = n.tmpl.Data(receiverName(ctx), groupLabels(ctx), as...)
...
}
A warning is defined as follows:
type Alert struct {
Labels LabelSet `json:"labels"`
Annotations LabelSet `json:"annotations"`
StartsAt time.Time `json:"startsAt,omitempty"`
EndsAt time.Time `json:"endsAt,omitempty"`
GeneratorURL string `json:"generatorURL"`
}
I would like to do a sort in the StartsAt field.
I tried using the sort function, but it was not available in the email template.
{{ range sort .Alerts.Firing }}
I get
function \"sort\" not defined
Any ideas on how I can sort it by StartsAt?
source
share