Expose alert interval in template data

This commit is contained in:
Fabian Reinartz 2016-02-12 11:00:33 +01:00
parent 0594d170f6
commit 24b8c22a83

View File

@ -19,6 +19,7 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"time"
tmplhtml "html/template" tmplhtml "html/template"
tmpltext "text/template" tmpltext "text/template"
@ -218,12 +219,12 @@ type Data struct {
// Alert holds one alert for notification templates. // Alert holds one alert for notification templates.
type Alert struct { type Alert struct {
Status string `json:"status"` Status string `json:"status"`
Labels KV `json:"labels"` Labels KV `json:"labels"`
Annotations KV `json:"annotations"` Annotations KV `json:"annotations"`
WasSilenced bool `json:"-"` StartsAt time.Time `json:"startsAt"`
WasInhibited bool `json:"-"` EndsAt time.Time `json:"endsAt"`
GeneratorURL string `json:"generatorURL"` GeneratorURL string `json:"generatorURL"`
} }
// Alerts is a list of Alert objects. // Alerts is a list of Alert objects.
@ -263,13 +264,15 @@ func (t *Template) Data(recv string, groupLabels model.LabelSet, alerts ...*type
ExternalURL: t.ExternalURL.String(), ExternalURL: t.ExternalURL.String(),
} }
for _, a := range alerts { // The call to types.Alert is necessary to correctly resolve the internal
// representation to the user representation.
for _, a := range types.Alerts(alerts...) {
alert := Alert{ alert := Alert{
Status: string(a.Status()), Status: string(a.Status()),
Labels: make(KV, len(a.Labels)), Labels: make(KV, len(a.Labels)),
Annotations: make(KV, len(a.Annotations)), Annotations: make(KV, len(a.Annotations)),
WasSilenced: a.WasSilenced, StartsAt: a.StartsAt,
WasInhibited: a.WasInhibited, EndsAt: a.EndsAt,
GeneratorURL: a.GeneratorURL, GeneratorURL: a.GeneratorURL,
} }
for k, v := range a.Labels { for k, v := range a.Labels {