mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 05:34:48 +02:00
Merge pull request #6217 from Icinga/fix/reschedule-checks
Fix check behavior on restart
This commit is contained in:
commit
c7b6488e90
@ -107,7 +107,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
|||||||
m_CheckRunning = false;
|
m_CheckRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cr)
|
if (!cr || !IsActive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
@ -428,8 +428,6 @@ void Checkable::ExecuteCheck()
|
|||||||
double scheduled_start = GetNextCheck();
|
double scheduled_start = GetNextCheck();
|
||||||
double before_check = Utility::GetTime();
|
double before_check = Utility::GetTime();
|
||||||
|
|
||||||
UpdateNextCheck();
|
|
||||||
|
|
||||||
bool reachable = IsReachable();
|
bool reachable = IsReachable();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -73,8 +73,11 @@ void Checkable::Start(bool runtimeCreated)
|
|||||||
{
|
{
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
if (GetNextCheck() < now + 300)
|
if (GetNextCheck() < now + 60) {
|
||||||
UpdateNextCheck();
|
double delta = std::min(GetCheckInterval(), 60.0);
|
||||||
|
delta *= (double)std::rand() / RAND_MAX;
|
||||||
|
SetNextCheck(now + delta);
|
||||||
|
}
|
||||||
|
|
||||||
ObjectImpl<Checkable>::Start(runtimeCreated);
|
ObjectImpl<Checkable>::Start(runtimeCreated);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ static void LogFlapping(const Checkable::Ptr& obj)
|
|||||||
static void LogHostStatus(const Host::Ptr &host)
|
static void LogHostStatus(const Host::Ptr &host)
|
||||||
{
|
{
|
||||||
std::cout << "Current status: state: " << host->GetState() << " state_type: " << host->GetStateType()
|
std::cout << "Current status: state: " << host->GetState() << " state_type: " << host->GetStateType()
|
||||||
<< " check attempt: " << host->GetCheckAttempt() << "/" << host->GetMaxCheckAttempts() << std::endl;
|
<< " check attempt: " << host->GetCheckAttempt() << "/" << host->GetMaxCheckAttempts() << " Active: " << host->IsActive() << std::endl;
|
||||||
}
|
}
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
@ -73,6 +73,7 @@ BOOST_AUTO_TEST_CASE(host_not_flapping)
|
|||||||
host->SetName("test");
|
host->SetName("test");
|
||||||
host->SetEnableFlapping(true);
|
host->SetEnableFlapping(true);
|
||||||
host->SetMaxCheckAttempts(5);
|
host->SetMaxCheckAttempts(5);
|
||||||
|
host->SetActive(true);
|
||||||
|
|
||||||
// Host otherwise is soft down
|
// Host otherwise is soft down
|
||||||
host->SetState(HostUp);
|
host->SetState(HostUp);
|
||||||
@ -116,6 +117,7 @@ BOOST_AUTO_TEST_CASE(host_flapping)
|
|||||||
host->SetName("test");
|
host->SetName("test");
|
||||||
host->SetEnableFlapping(true);
|
host->SetEnableFlapping(true);
|
||||||
host->SetMaxCheckAttempts(5);
|
host->SetMaxCheckAttempts(5);
|
||||||
|
host->SetActive(true);
|
||||||
|
|
||||||
Utility::SetTime(0);
|
Utility::SetTime(0);
|
||||||
|
|
||||||
@ -150,6 +152,7 @@ BOOST_AUTO_TEST_CASE(host_flapping_recover)
|
|||||||
host->SetName("test");
|
host->SetName("test");
|
||||||
host->SetEnableFlapping(true);
|
host->SetEnableFlapping(true);
|
||||||
host->SetMaxCheckAttempts(5);
|
host->SetMaxCheckAttempts(5);
|
||||||
|
host->SetActive(true);
|
||||||
|
|
||||||
// Host otherwise is soft down
|
// Host otherwise is soft down
|
||||||
host->SetState(HostUp);
|
host->SetState(HostUp);
|
||||||
@ -209,6 +212,7 @@ BOOST_AUTO_TEST_CASE(host_flapping_docs_example)
|
|||||||
host->SetName("test");
|
host->SetName("test");
|
||||||
host->SetEnableFlapping(true);
|
host->SetEnableFlapping(true);
|
||||||
host->SetMaxCheckAttempts(5);
|
host->SetMaxCheckAttempts(5);
|
||||||
|
host->SetActive(true);
|
||||||
|
|
||||||
// Host otherwise is soft down
|
// Host otherwise is soft down
|
||||||
host->SetState(HostUp);
|
host->SetState(HostUp);
|
||||||
|
@ -63,6 +63,7 @@ BOOST_AUTO_TEST_CASE(host_1attempt)
|
|||||||
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
||||||
|
|
||||||
Host::Ptr host = new Host();
|
Host::Ptr host = new Host();
|
||||||
|
host->SetActive(true);
|
||||||
host->SetMaxCheckAttempts(1);
|
host->SetMaxCheckAttempts(1);
|
||||||
host->Activate();
|
host->Activate();
|
||||||
host->SetAuthority(true);
|
host->SetAuthority(true);
|
||||||
@ -111,6 +112,7 @@ BOOST_AUTO_TEST_CASE(host_2attempts)
|
|||||||
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
||||||
|
|
||||||
Host::Ptr host = new Host();
|
Host::Ptr host = new Host();
|
||||||
|
host->SetActive(true);
|
||||||
host->SetMaxCheckAttempts(2);
|
host->SetMaxCheckAttempts(2);
|
||||||
host->Activate();
|
host->Activate();
|
||||||
host->SetAuthority(true);
|
host->SetAuthority(true);
|
||||||
@ -166,6 +168,7 @@ BOOST_AUTO_TEST_CASE(host_3attempts)
|
|||||||
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
||||||
|
|
||||||
Host::Ptr host = new Host();
|
Host::Ptr host = new Host();
|
||||||
|
host->SetActive(true);
|
||||||
host->SetMaxCheckAttempts(3);
|
host->SetMaxCheckAttempts(3);
|
||||||
host->Activate();
|
host->Activate();
|
||||||
host->SetAuthority(true);
|
host->SetAuthority(true);
|
||||||
@ -228,6 +231,7 @@ BOOST_AUTO_TEST_CASE(service_1attempt)
|
|||||||
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
||||||
|
|
||||||
Service::Ptr service = new Service();
|
Service::Ptr service = new Service();
|
||||||
|
service->SetActive(true);
|
||||||
service->SetMaxCheckAttempts(1);
|
service->SetMaxCheckAttempts(1);
|
||||||
service->Activate();
|
service->Activate();
|
||||||
service->SetAuthority(true);
|
service->SetAuthority(true);
|
||||||
@ -276,6 +280,7 @@ BOOST_AUTO_TEST_CASE(service_2attempts)
|
|||||||
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
||||||
|
|
||||||
Service::Ptr service = new Service();
|
Service::Ptr service = new Service();
|
||||||
|
service->SetActive(true);
|
||||||
service->SetMaxCheckAttempts(2);
|
service->SetMaxCheckAttempts(2);
|
||||||
service->Activate();
|
service->Activate();
|
||||||
service->SetAuthority(true);
|
service->SetAuthority(true);
|
||||||
@ -331,6 +336,7 @@ BOOST_AUTO_TEST_CASE(service_3attempts)
|
|||||||
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
|
||||||
|
|
||||||
Service::Ptr service = new Service();
|
Service::Ptr service = new Service();
|
||||||
|
service->SetActive(true);
|
||||||
service->SetMaxCheckAttempts(3);
|
service->SetMaxCheckAttempts(3);
|
||||||
service->Activate();
|
service->Activate();
|
||||||
service->SetAuthority(true);
|
service->SetAuthority(true);
|
||||||
@ -398,6 +404,7 @@ BOOST_AUTO_TEST_CASE(host_flapping_notification)
|
|||||||
int timeStepInterval = 60;
|
int timeStepInterval = 60;
|
||||||
|
|
||||||
Host::Ptr host = new Host();
|
Host::Ptr host = new Host();
|
||||||
|
host->SetActive(true);
|
||||||
host->Activate();
|
host->Activate();
|
||||||
host->SetAuthority(true);
|
host->SetAuthority(true);
|
||||||
host->SetStateRaw(ServiceOK);
|
host->SetStateRaw(ServiceOK);
|
||||||
@ -451,6 +458,7 @@ BOOST_AUTO_TEST_CASE(service_flapping_notification)
|
|||||||
int timeStepInterval = 60;
|
int timeStepInterval = 60;
|
||||||
|
|
||||||
Service::Ptr service = new Service();
|
Service::Ptr service = new Service();
|
||||||
|
service->SetActive(true);
|
||||||
service->Activate();
|
service->Activate();
|
||||||
service->SetAuthority(true);
|
service->SetAuthority(true);
|
||||||
service->SetStateRaw(ServiceOK);
|
service->SetStateRaw(ServiceOK);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user