Hide resolved it alert JSON if it was added via timeout

This commit is contained in:
Fabian Reinartz 2015-09-30 14:53:05 +02:00
parent d4ec632d06
commit 006939de12
2 changed files with 16 additions and 4 deletions

6
api.go
View File

@ -78,15 +78,17 @@ func (api *API) addAlerts(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
for _, alert := range alerts {
now := time.Now()
now := time.Now()
for _, alert := range alerts {
alert.UpdatedAt = now
if alert.StartsAt.IsZero() {
alert.StartsAt = now
}
if alert.EndsAt.IsZero() {
alert.Timeout = true
alert.EndsAt = alert.StartsAt.Add(ResolveTimeout)
}
}

View File

@ -32,13 +32,23 @@ type Alert struct {
Labels model.LabelSet `json:"labels"`
// Extra key/value information which does not define alert identity.
Annotations Annotations `json:"annotations,omitempty"`
Annotations Annotations `json:"annotations"`
StartsAt time.Time `json:"startsAt,omitempty"`
EndsAt time.Time `json:"endsAt,omitempty"`
// The authoritative timestamp.
UpdatedAt time.Time `json:"timestamp"`
UpdatedAt time.Time `json:"-"`
Timeout bool `json:"-"`
}
func (a *Alert) MarshalJSON() ([]byte, error) {
b := *a
if b.Timeout {
b.EndsAt = time.Time{}
}
return json.Marshal(b)
}
// Name returns the name of the alert. It is equivalent to the "alertname" label.