Skip to content

Commit

Permalink
Ignore state change events while in downtime/flapping state
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Apr 26, 2024
1 parent aa3b67e commit 0ff79aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/icinga2/api_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type HostServiceRuntimeAttributes struct {
Groups []string `json:"groups"`
State int `json:"state"`
StateType int `json:"state_type"`
IsFlapping bool `json:"flapping"`
LastCheckResult CheckResult `json:"last_check_result"`
LastStateChange UnixFloat `json:"last_state_change"`
DowntimeDepth int `json:"downtime_depth"`
Expand Down
25 changes: 24 additions & 1 deletion internal/icinga2/client_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca
return fmt.Errorf("querying API delivered a wrong object type %q", objQueriesResult.Type)
}

// Downtime suppresses all kind of events on that checkable, so skip it if it's in downtime.
if objQueriesResult.Attrs.DowntimeDepth > 0 {
continue
}

// If the checkable is not in downtime but in flapping state, all other states/events become irrelevant as well.
if objQueriesResult.Attrs.IsFlapping {
continue
}

// Only process HARD states
if objQueriesResult.Attrs.StateType == StateTypeSoft {
client.Logger.Debugf("Skipping SOFT event, %#v", objQueriesResult.Attrs)
Expand Down Expand Up @@ -428,7 +438,20 @@ func (client *Client) listenEventStream() error {
)
switch respT := resp.(type) {
case *StateChange:
// Only process HARD states
// Ignore any state changes while in downtime
if respT.DowntimeDepth > 0 {
stateType := "HARD"
if respT.StateType == StateTypeSoft {
stateType = "SOFT"
}

client.Logger.Debugf("Skipping %q state change while in downtime, %#v", stateType, respT)
continue
}

// Only process HARD states.
// The checkable might also be in the flapping state, but Icinga 2 doesn't expose "is_flapping" to the
// event streams for state change. So, the only thing we can do here is to ignore soft state changes.
if respT.StateType == StateTypeSoft {
client.Logger.Debugf("Skipping SOFT State Change, %#v", respT)
continue
Expand Down

0 comments on commit 0ff79aa

Please sign in to comment.