diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index b9ffe19e67f..73f15dd1af8 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -224,7 +224,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig } /* SOFT state change, increase attempt counter. */ - if (old_stateType == StateTypeSoft && !IsStateOK(old_state)) { + if (old_stateType == StateTypeSoft && old_cr && !IsStateOK(old_state)) { SetStateType(StateTypeSoft); attempt = old_attempt + 1; } @@ -268,11 +268,15 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig bool stateChange; - /* Exception on state change calculation for hosts. */ - if (checkableType == CheckableService) - stateChange = (old_state != new_state); - else - stateChange = (Host::CalculateState(old_state) != Host::CalculateState(new_state)); + if (old_cr) { + /* Exception on state change calculation for hosts. */ + if (checkableType == CheckableService) + stateChange = (old_state != new_state); + else + stateChange = (Host::CalculateState(old_state) != Host::CalculateState(new_state)); + } else { + stateChange = true; + } /* Store the current last state change for the next iteration. */ SetPreviousStateChange(GetLastStateChange()); @@ -306,9 +310,9 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig if (GetAcknowledgement() == AcknowledgementNone) remove_acknowledgement_comments = true; - bool hardChange = (GetStateType() == StateTypeHard && old_stateType == StateTypeSoft); + bool hardChange = (GetStateType() == StateTypeHard && old_stateType == StateTypeSoft && old_cr); - if (stateChange && old_stateType == StateTypeHard && GetStateType() == StateTypeHard) + if (stateChange && (old_stateType == StateTypeHard || !old_cr) && GetStateType() == StateTypeHard) hardChange = true; bool is_volatile = GetVolatile(); @@ -430,13 +434,13 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig if (hardChange || (is_volatile && !(IsStateOK(old_state) && IsStateOK(new_state)))) { OnStateChange(this, cr, StateTypeHard, origin); Log(LogNotice, "Checkable") - << "State Change: Checkable '" << GetName() << "' hard state change from " << old_state_str << " to " << new_state_str << " detected." << (is_volatile ? " Checkable is volatile." : ""); + << "State Change: Checkable '" << GetName() << "' hard state change from " << old_state_str << (old_cr ? "" : " (pending)") << " to " << new_state_str << " detected." << (is_volatile ? " Checkable is volatile." : ""); } /* Whether a state change happened or the state type is SOFT (must be logged too). */ else if (stateChange || GetStateType() == StateTypeSoft) { OnStateChange(this, cr, StateTypeSoft, origin); Log(LogNotice, "Checkable") - << "State Change: Checkable '" << GetName() << "' soft state change from " << old_state_str << " to " << new_state_str << " detected."; + << "State Change: Checkable '" << GetName() << "' soft state change from " << old_state_str << (old_cr ? "" : " (pending)") << " to " << new_state_str << " detected."; } if (GetStateType() == StateTypeSoft || hardChange || recovery ||