From: Gunnar Beutner Date: Fri, 21 Jun 2013 08:28:21 +0000 (+0200) Subject: Implement external commands for flapping detection. X-Git-Tag: v0.0.2~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f158ff793a3bbf9f93395fffdcecccec1bfec4a;p=icinga2 Implement external commands for flapping detection. --- diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 9df83df2f..06f6d9309 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -520,7 +520,7 @@ void CompatComponent::StatusTimerHandler(void) << "\t" << "check_service_freshness=0" << "\n" << "\t" << "check_host_freshness=0" << "\n" << "\t" << "enable_notifications=1" << "\n" - << "\t" << "enable_flap_detection=0" << "\n" + << "\t" << "enable_flap_detection=1" << "\n" << "\t" << "enable_failure_prediction=0" << "\n" << "\t" << "active_scheduled_service_check_stats=" << CIB::GetActiveChecksStatistics(60) << "," << CIB::GetActiveChecksStatistics(5 * 60) << "," << CIB::GetActiveChecksStatistics(15 * 60) << "\n" << "\t" << "passive_service_check_stats=" << CIB::GetPassiveChecksStatistics(60) << "," << CIB::GetPassiveChecksStatistics(5 * 60) << "," << CIB::GetPassiveChecksStatistics(15 * 60) << "\n" diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index dc4e04aad..c424d054b 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -1429,3 +1429,75 @@ void ExternalCommandProcessor::EnableServicegroupPassiveHostChecks(double, const } } } + +void ExternalCommandProcessor::EnableHostFlapping(double, const std::vector& arguments) +{ + if (arguments.size() < 1) + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); + + Host::Ptr host = Host::GetByName(arguments[0]); + + Log(LogInformation, "icinga", "Enabling flapping detection for host '" + arguments[0] + "'"); + Service::Ptr hc = host->GetHostCheckService(); + + if (!hc) + return; + + { + ObjectLock olock(hc); + + hc->SetEnableFlapping(true); + } +} + +void ExternalCommandProcessor::DisableHostFlapping(double, const std::vector& arguments) +{ + if (arguments.size() < 1) + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); + + Host::Ptr host = Host::GetByName(arguments[0]); + + Log(LogInformation, "icinga", "Disabling flapping detection for host '" + arguments[0] + "'"); + Service::Ptr hc = host->GetHostCheckService(); + + if (!hc) + return; + + { + ObjectLock olock(hc); + + hc->SetEnableFlapping(false); + } +} + +void ExternalCommandProcessor::EnableSvcFlapping(double, const std::vector& arguments) +{ + if (arguments.size() < 2) + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); + + Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); + + Log(LogInformation, "icinga", "Enabling flapping detection for service '" + arguments[1] + "'"); + + { + ObjectLock olock(service); + + service->SetEnableFlapping(true); + } +} + +void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vector& arguments) +{ + if (arguments.size() < 2) + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); + + Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); + + Log(LogInformation, "icinga", "Disabling flapping detection for service '" + arguments[1] + "'"); + + { + ObjectLock olock(service); + + service->SetEnableFlapping(false); + } +} \ No newline at end of file diff --git a/lib/icinga/externalcommandprocessor.h b/lib/icinga/externalcommandprocessor.h index ab77e480a..635e5885b 100644 --- a/lib/icinga/externalcommandprocessor.h +++ b/lib/icinga/externalcommandprocessor.h @@ -113,6 +113,10 @@ private: static void EnableHostgroupPassiveHostChecks(double, const std::vector& arguments); static void EnableServicegroupHostChecks(double, const std::vector& arguments); static void EnableServicegroupPassiveHostChecks(double, const std::vector& arguments); + static void EnableSvcFlapping(double time, const std::vector& arguments); + static void DisableSvcFlapping(double time, const std::vector& arguments); + static void EnableHostFlapping(double time, const std::vector& arguments); + static void DisableHostFlapping(double time, const std::vector& arguments); }; } diff --git a/lib/icinga/service-flapping.cpp b/lib/icinga/service-flapping.cpp index ca8125914..754cb27f9 100644 --- a/lib/icinga/service-flapping.cpp +++ b/lib/icinga/service-flapping.cpp @@ -31,6 +31,21 @@ using namespace icinga; #define FLAPPING_INTERVAL (30 * 60) +bool Service::GetEnableFlapping(void) const +{ + if (m_EnableFlapping.IsEmpty()) + return true; + else + return m_EnableFlapping; + +} + +void Service::SetEnableFlapping(bool enabled) +{ + m_EnableFlapping = enabled ? 1 : 0; + Touch("enable_flapping"); +} + void Service::UpdateFlappingStatus(bool stateChange) { double ts, now; diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 63edfae1a..0a0394f7e 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -86,6 +86,7 @@ Service::Service(const Dictionary::Ptr& serializedObject) RegisterAttribute("flapping_counter", Attribute_Replicated, &m_FlappingCounter); RegisterAttribute("flapping_lastchange", Attribute_Replicated, &m_FlappingLastChange); RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold); + RegisterAttribute("enable_flapping", Attribute_Config, &m_EnableFlapping); SetSchedulingOffset(rand()); } diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 664fcd22d..bc722573e 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -249,6 +249,9 @@ public: shared_ptr GetEventCommand(void) const; /* Flapping Detection */ + bool GetEnableFlapping(void) const; + void SetEnableFlapping(bool enabled); + bool IsFlapping(void) const; void UpdateFlappingStatus(bool stateChange); @@ -325,6 +328,7 @@ private: Attribute m_EventCommand; /* Flapping */ + Attribute m_EnableFlapping; Attribute m_FlappingCounter; Attribute m_FlappingLastChange; Attribute m_FlappingThreshold;