Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize PENDING -> UNKNOWN as state change #7815

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/icinga/checkable-check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 ||
Expand Down