Skip to content

Commit 0ff79aa

Browse files
committed
Ignore state change events while in downtime/flapping state
1 parent aa3b67e commit 0ff79aa

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: internal/icinga2/api_responses.go

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type HostServiceRuntimeAttributes struct {
132132
Groups []string `json:"groups"`
133133
State int `json:"state"`
134134
StateType int `json:"state_type"`
135+
IsFlapping bool `json:"flapping"`
135136
LastCheckResult CheckResult `json:"last_check_result"`
136137
LastStateChange UnixFloat `json:"last_state_change"`
137138
DowntimeDepth int `json:"downtime_depth"`

Diff for: internal/icinga2/client_api.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca
230230
return fmt.Errorf("querying API delivered a wrong object type %q", objQueriesResult.Type)
231231
}
232232

233+
// Downtime suppresses all kind of events on that checkable, so skip it if it's in downtime.
234+
if objQueriesResult.Attrs.DowntimeDepth > 0 {
235+
continue
236+
}
237+
238+
// If the checkable is not in downtime but in flapping state, all other states/events become irrelevant as well.
239+
if objQueriesResult.Attrs.IsFlapping {
240+
continue
241+
}
242+
233243
// Only process HARD states
234244
if objQueriesResult.Attrs.StateType == StateTypeSoft {
235245
client.Logger.Debugf("Skipping SOFT event, %#v", objQueriesResult.Attrs)
@@ -428,7 +438,20 @@ func (client *Client) listenEventStream() error {
428438
)
429439
switch respT := resp.(type) {
430440
case *StateChange:
431-
// Only process HARD states
441+
// Ignore any state changes while in downtime
442+
if respT.DowntimeDepth > 0 {
443+
stateType := "HARD"
444+
if respT.StateType == StateTypeSoft {
445+
stateType = "SOFT"
446+
}
447+
448+
client.Logger.Debugf("Skipping %q state change while in downtime, %#v", stateType, respT)
449+
continue
450+
}
451+
452+
// Only process HARD states.
453+
// The checkable might also be in the flapping state, but Icinga 2 doesn't expose "is_flapping" to the
454+
// event streams for state change. So, the only thing we can do here is to ignore soft state changes.
432455
if respT.StateType == StateTypeSoft {
433456
client.Logger.Debugf("Skipping SOFT State Change, %#v", respT)
434457
continue

0 commit comments

Comments
 (0)