Fix Flapping{Start,End} notifications in SOFT states or downtimes

fixes #12560
fixes #12892
This commit is contained in:
Michael Friedrich 2016-11-10 14:02:02 +01:00
parent 06e4b4e9da
commit 7e0c48643b
3 changed files with 101 additions and 2 deletions

View File

@ -368,7 +368,8 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
ExecuteEventHandler();
/* Flapping start/end notifications */
if (!was_flapping && is_flapping) {
if (send_notification && !was_flapping && is_flapping) {
/* FlappingStart notifications happen on state changes, not in downtimes */
if (!IsPaused())
OnNotificationsRequested(this, NotificationFlappingStart, cr, "", "", MessageOrigin::Ptr());
@ -376,7 +377,8 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
<< "Flapping: Checkable " << GetName() << " started flapping (" << GetFlappingThreshold() << "% < " << GetFlappingCurrent() << "%).";
NotifyFlapping(origin);
} else if (was_flapping && !is_flapping) {
} else if (!in_downtime && was_flapping && !is_flapping) {
/* FlappingEnd notifications are independent from state changes, must not happen in downtine */
if (!IsPaused())
OnNotificationsRequested(this, NotificationFlappingEnd, cr, "", "", MessageOrigin::Ptr());

View File

@ -97,6 +97,8 @@ add_boost_test(base
icinga_checkresult/service_1attempt
icinga_checkresult/service_2attempts
icinga_checkresult/service_3attempts
icinga_checkresult/host_flapping_notification
icinga_checkresult/service_flapping_notification
icinga_macros/simple
icinga_perfdata/empty
icinga_perfdata/simple

View File

@ -387,4 +387,99 @@ BOOST_AUTO_TEST_CASE(service_3attempts)
c.disconnect();
}
BOOST_AUTO_TEST_CASE(host_flapping_notification)
{
#ifndef I2_DEBUG
BOOST_WARN_MESSAGE(false, "This test can only be run in a debug build!");
#else /* I2_DEBUG */
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(boost::bind(&NotificationHandler, _1, _2));
int softStateCount = 20;
int timeStepInterval = 60;
Host::Ptr host = new Host();
host->SetMaxCheckAttempts(softStateCount);
host->Activate();
host->SetAuthority(true);
host->SetStateRaw(ServiceOK);
host->SetStateType(StateTypeHard);
host->SetEnableFlapping(true);
/* Initialize start time */
Utility::SetTime(0);
std::cout << "Before first check result (ok, hard)" << std::endl;
BOOST_CHECK(host->GetState() == HostUp);
BOOST_CHECK(host->GetStateType() == StateTypeHard);
BOOST_CHECK(host->GetCheckAttempt() == 1);
Utility::IncrementTime(timeStepInterval);
std::cout << "Inserting flapping check results" << std::endl;
for (int i = 0; i < softStateCount; i++) {
ServiceState state = (i % 2 == 0 ? ServiceOK : ServiceCritical);
host->ProcessCheckResult(MakeCheckResult(state));
Utility::IncrementTime(timeStepInterval);
}
std::cout << "Checking host state (must be flapping in SOFT state)" << std::endl;
BOOST_CHECK(host->GetStateType() == StateTypeSoft);
BOOST_CHECK(host->IsFlapping() == true);
std::cout << "No FlappingStart notification type must have been triggered in a SOFT state" << std::endl;
CheckNotification(host, false, NotificationFlappingStart);
c.disconnect();
#endif /* I2_DEBUG */
}
BOOST_AUTO_TEST_CASE(service_flapping_notification)
{
#ifndef I2_DEBUG
BOOST_WARN_MESSAGE(false, "This test can only be run in a debug build!");
#else /* I2_DEBUG */
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(boost::bind(&NotificationHandler, _1, _2));
int softStateCount = 20;
int timeStepInterval = 60;
Host::Ptr service = new Host();
service->SetMaxCheckAttempts(softStateCount);
service->Activate();
service->SetAuthority(true);
service->SetStateRaw(ServiceOK);
service->SetStateType(StateTypeHard);
service->SetEnableFlapping(true);
/* Initialize start time */
Utility::SetTime(0);
std::cout << "Before first check result (ok, hard)" << std::endl;
BOOST_CHECK(service->GetState() == HostUp);
BOOST_CHECK(service->GetStateType() == StateTypeHard);
BOOST_CHECK(service->GetCheckAttempt() == 1);
Utility::IncrementTime(timeStepInterval);
std::cout << "Inserting flapping check results" << std::endl;
for (int i = 0; i < softStateCount; i++) {
ServiceState state = (i % 2 == 0 ? ServiceOK : ServiceCritical);
service->ProcessCheckResult(MakeCheckResult(state));
Utility::IncrementTime(timeStepInterval);
}
std::cout << "Checking service state (must be flapping in SOFT state)" << std::endl;
BOOST_CHECK(service->GetStateType() == StateTypeSoft);
BOOST_CHECK(service->IsFlapping() == true);
std::cout << "No FlappingStart notification type must have been triggered in a SOFT state" << std::endl;
CheckNotification(service, false, NotificationFlappingStart);
c.disconnect();
#endif /* I2_DEBUG */
}
BOOST_AUTO_TEST_SUITE_END()