Merge pull request #8436 from Icinga/bugfix/children-recover-too-late

On recovery: re-check children
This commit is contained in:
Alexander Aleksandrovič Klimov 2020-12-11 15:41:31 +01:00 committed by GitHub
commit 915a3c3001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 22 deletions

View File

@ -242,6 +242,20 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
OnReachabilityChanged(this, cr, children, origin); OnReachabilityChanged(this, cr, children, origin);
} }
if (recovery) {
for (auto& child : children) {
if (child->GetProblem() && child->GetEnableActiveChecks()) {
auto nextCheck (now + Utility::Random() % 60);
ObjectLock oLock (child);
if (nextCheck < child->GetNextCheck()) {
child->SetNextCheck(nextCheck);
}
}
}
}
if (!reachable) if (!reachable)
SetLastStateUnreachable(cr->GetExecutionEnd()); SetLastStateUnreachable(cr->GetExecutionEnd());

View File

@ -10,6 +10,7 @@
#include "base/exception.hpp" #include "base/exception.hpp"
#include "base/context.hpp" #include "base/context.hpp"
#include "base/convert.hpp" #include "base/convert.hpp"
#include "base/lazy-init.hpp"
#include "remote/apilistener.hpp" #include "remote/apilistener.hpp"
using namespace icinga; using namespace icinga;
@ -145,6 +146,28 @@ static void FireSuppressedNotifications(Checkable* checkable)
int subtract = 0; int subtract = 0;
{
LazyInit<bool> wasLastParentRecoveryRecent ([&checkable]() {
auto cr (checkable->GetLastCheckResult());
if (!cr) {
return true;
}
auto threshold (cr->GetExecutionStart());
for (auto& dep : checkable->GetDependencies()) {
auto parent (dep->GetParent());
ObjectLock oLock (parent);
if (!parent->GetProblem() && parent->GetLastStateChange() >= threshold) {
return true;
}
}
return false;
});
for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) { for (auto type : {NotificationProblem, NotificationRecovery, NotificationFlappingStart, NotificationFlappingEnd}) {
if (suppressed_types & type) { if (suppressed_types & type) {
bool still_applies = checkable->NotificationReasonApplies(type); bool still_applies = checkable->NotificationReasonApplies(type);
@ -167,7 +190,7 @@ static void FireSuppressedNotifications(Checkable* checkable)
break; break;
} }
if (!still_suppressed && !checkable->IsLikelyToBeCheckedSoon()) { if (!still_suppressed && !checkable->IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) {
Checkable::OnNotificationsRequested(checkable, type, checkable->GetLastCheckResult(), "", "", nullptr); Checkable::OnNotificationsRequested(checkable, type, checkable->GetLastCheckResult(), "", "", nullptr);
subtract |= type; subtract |= type;
@ -177,6 +200,7 @@ static void FireSuppressedNotifications(Checkable* checkable)
} }
} }
} }
}
if (subtract) { if (subtract) {
ObjectLock olock (checkable); ObjectLock olock (checkable);