Use alert status, inhibitedBy & silencedBy fields instead of silenced & inhibited

This commit is contained in:
Łukasz Mierzwa
2017-05-01 20:21:09 +01:00
parent 5df44def81
commit 487d7bcde8
16 changed files with 183 additions and 127 deletions

View File

@@ -23,6 +23,23 @@ type Silence struct {
JiraURL string `json:"jiraURL"`
}
// AlertStateUnprocessed means that Alertmanager notify didn't yet process it
// and AM doesn't know if alert is active or suppressed
const AlertStateUnprocessed = "unprocessed"
// AlertStateActive is the state in which we know that the alert should fire
const AlertStateActive = "active"
// AlertStateSuppressed means that we know that alert is silenced or inhibited
const AlertStateSuppressed = "suppressed"
// AlertStateList exports all alert states so other packages can get this list
var AlertStateList = []string{
AlertStateUnprocessed,
AlertStateActive,
AlertStateSuppressed,
}
// Alert is vanilla alert + some additional attributes
// unsee extends an alert object with:
// * Links map, it's generated from annotations if annotation value is an url
@@ -35,16 +52,29 @@ type Alert struct {
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
GeneratorURL string `json:"generatorURL"`
Status string `json:"Status"`
Status string `json:"status"`
SilencedBy []string `json:"silencedBy"`
InhibitedBy []string `json:"inhibitedBy"`
Inhibited bool `json:"inhibited"`
Silenced string `json:"silenced"`
// unsee fields
Links map[string]string `json:"links"`
Fingerprint string `json:"-"`
}
// IsSilenced will return true if alert should be considered silenced
func (a Alert) IsSilenced() bool {
return (a.Status == AlertStateSuppressed && len(a.SilencedBy) > 0)
}
// IsInhibited will return true if alert should be considered silenced
func (a Alert) IsInhibited() bool {
return (a.Status == AlertStateSuppressed && len(a.InhibitedBy) > 0)
}
// IsActive will return true if alert is not suppressed in any way
func (a Alert) IsActive() bool {
return (a.Status == AlertStateActive)
}
// AlertList is flat list of UnseeAlert objects
type AlertList []Alert