]> granicus.if.org Git - icinga2/commitdiff
Implement external commands for flapping detection.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 21 Jun 2013 08:28:21 +0000 (10:28 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 21 Jun 2013 08:28:21 +0000 (10:28 +0200)
components/compat/compatcomponent.cpp
lib/icinga/externalcommandprocessor.cpp
lib/icinga/externalcommandprocessor.h
lib/icinga/service-flapping.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index 9df83df2f5c96a1099da02bc621cbecd21d88d6b..06f6d9309939158d0b9698af0d49efee2b63e2c4 100644 (file)
@@ -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"
index dc4e04aad5e8f0e6f4b34c2012cb8928ea204bc9..c424d054bc9cd9253509f0f8abe0ea0665967ab0 100644 (file)
@@ -1429,3 +1429,75 @@ void ExternalCommandProcessor::EnableServicegroupPassiveHostChecks(double, const
                }
        }
 }
+
+void ExternalCommandProcessor::EnableHostFlapping(double, const std::vector<String>& 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<String>& 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<String>& 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<String>& 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
index ab77e480a84660dbcbf01508c23c1d67f18b60d3..635e5885b77ab99a48f0c95aa0649457d8dfdd8c 100644 (file)
@@ -113,6 +113,10 @@ private:
        static void EnableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments);
        static void EnableServicegroupHostChecks(double, const std::vector<String>& arguments);
        static void EnableServicegroupPassiveHostChecks(double, const std::vector<String>& arguments);
+       static void EnableSvcFlapping(double time, const std::vector<String>& arguments);
+       static void DisableSvcFlapping(double time, const std::vector<String>& arguments);
+       static void EnableHostFlapping(double time, const std::vector<String>& arguments);
+       static void DisableHostFlapping(double time, const std::vector<String>& arguments);
 };
 
 }
index ca812591477ad67a8056926715bfb2fc6b240264..754cb27f9214e4989fea0a5ef2db1a86cc0031fd 100644 (file)
@@ -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;
index 63edfae1afbad684de3fc1f6392a97102ff13c14..0a0394f7e47348f25fe76dd96ad279de256fadde 100644 (file)
@@ -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());
 }
index 664fcd22dde7d137eefd04eafce58abca72029a6..bc722573e064f61e221508ce48b8c0c11584e6f6 100644 (file)
@@ -249,6 +249,9 @@ public:
        shared_ptr<EventCommand> 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<String> m_EventCommand;
 
        /* Flapping */
+       Attribute<bool> m_EnableFlapping;
        Attribute<long> m_FlappingCounter;
        Attribute<double> m_FlappingLastChange;
        Attribute<double> m_FlappingThreshold;