【发布时间】:2017-01-06 12:24:41
【问题描述】:
我正在尝试从 AlertManager 自定义电子邮件模板,该模板使用 Go html 模板,该模板使用以下构造打印警报列表:
{{ range .Alerts.Firing }}
它像这样插入到模板中:
func (n *Email) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
...
data = n.tmpl.Data(receiverName(ctx), groupLabels(ctx), as...)
...
}
警报是这样定义的:
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"`
}
我想对 StartsAt 字段进行排序。
我尝试使用排序功能,但它在电子邮件模板中不可用。
{{ range sort .Alerts.Firing }}
我来了
function \"sort\" not defined
关于如何让它在 StartsAt 上排序的任何想法?
【问题讨论】:
标签: go go-templates prometheus