Hide resolved it alert JSON if it was added via timeout
This commit is contained in:
parent
d4ec632d06
commit
006939de12
6
api.go
6
api.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue