From: Jean Flach Date: Tue, 10 Apr 2018 13:50:45 +0000 (+0200) Subject: Fix check behavior on restart X-Git-Tag: v2.9.0~88^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a9c1591c0c13603b1dee6cfb514e6ec7c309450;p=icinga2 Fix check behavior on restart This patch changes the way checkresults are handled during a restart. 1. Check results coming in during a shutdown are ignored. 2. Upon start, checks which should have ran (next_check in the past), are re-scheduled within the first minute. This new behavior means there will be no more "Unknown - Terminated" checkresults during a restart and checks with high check_interval will be run earlier if they were already scheduled to run. The downside is that after Icinga2 was down for a while, there will be a lot of checks within the first minute. Our max concurrent check should take care of this though. --- diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index 8bf1fed74..76b2cc37e 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -107,7 +107,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig m_CheckRunning = false; } - if (!cr) + if (!cr || !IsActive()) return; double now = Utility::GetTime(); @@ -428,8 +428,6 @@ void Checkable::ExecuteCheck() double scheduled_start = GetNextCheck(); double before_check = Utility::GetTime(); - UpdateNextCheck(); - bool reachable = IsReachable(); { diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 69af2c581..fe52e37ef 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -73,8 +73,11 @@ void Checkable::Start(bool runtimeCreated) { double now = Utility::GetTime(); - if (GetNextCheck() < now + 300) - UpdateNextCheck(); + if (GetNextCheck() < now + 60) { + double delta = std::min(GetCheckInterval(), 60.0); + delta *= (double)std::rand() / RAND_MAX; + SetNextCheck(now + delta); + } ObjectImpl::Start(runtimeCreated); }