]> granicus.if.org Git - icinga2/commitdiff
flapping: fix division by 0, add compat status, extcmds
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 15:25:30 +0000 (17:25 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 15:25:30 +0000 (17:25 +0200)
and some debug output.

refs #4360
refs #2711

components/compat/compatcomponent.cpp
lib/icinga/externalcommandprocessor.cpp
lib/icinga/service-check.cpp
lib/icinga/service-flapping.cpp

index 16b7aba4f154de9b11dda9f10f274933b0dcad80..096fad4706a5730cdbbe646f873e6ce53b521499 100644 (file)
@@ -413,6 +413,9 @@ void CompatComponent::DumpServiceStatusAttrs(std::ostream& fp, const Service::Pt
           << "\t" << "notifications_enabled=" << (service->GetEnableNotifications() ? 1 : 0) << "\n"
           << "\t" << "active_checks_enabled=" << (service->GetEnableActiveChecks() ? 1 : 0) <<"\n"
           << "\t" << "passive_checks_enabled=" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
+          << "\t" << "flap_detection_enabled=" << "\t" << (service->GetEnableFlapping() ? 1 : 0) << "\n"
+          << "\t" << "is_flapping=" << "\t" << (service->IsFlapping() ? 1 : 0) << "\n"
+          << "\t" << "percent_state_change=" << "\t" << Convert::ToString(service->GetFlappingCurrent()) << "\n"
           << "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
           << "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
           << "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
index aba9168c2932435888102c91ffb7ffa26581686e..717f7f00367264dd9b4a393d74f94138c17ec93c 100644 (file)
@@ -118,6 +118,10 @@ void ExternalCommandProcessor::Initialize(void)
        RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM", &ExternalCommandProcessor::AcknowledgeHostProblem);
        RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeHostProblemExpire);
        RegisterCommand("REMOVE_HOST_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveHostAcknowledgement);
+       RegisterCommand("DISABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::DisableHostFlapping);
+       RegisterCommand("ENABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::EnableHostFlapping);
+       RegisterCommand("DISABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::DisableSvcFlapping);
+       RegisterCommand("ENABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::EnableSvcFlapping);
        RegisterCommand("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupSvcChecks);
        RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupSvcChecks);
        RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupSvcChecks);
index 961c21d919f0aefec5b8b4923ea560482838b585..5badf7521bdbf21801502583571d453574f8f08f 100644 (file)
@@ -27,6 +27,7 @@
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
 #include "base/logger_fwd.h"
+#include "base/convert.h"
 #include <boost/smart_ptr/make_shared.hpp>
 #include <boost/foreach.hpp>
 #include <boost/exception/diagnostic_information.hpp>
@@ -460,6 +461,13 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
        olock.Unlock();
 
+       Log(LogDebug, "icinga", "Flapping: Service " +
+                       GetName() + " was: " +
+                       Convert::ToString(was_flapping) + " is: " +
+                       Convert::ToString(was_flapping) + " threshold: " +
+                       Convert::ToString(GetFlappingThreshold()) + "% current: " +
+                       Convert::ToString(GetFlappingCurrent()) + "%.");
+
        /* Flush the object so other instances see the service's
         * new state when they receive the CheckResult message */
        Flush();
@@ -495,6 +503,8 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
                rm.SetParams(params);
 
                EndpointManager::GetInstance()->SendMulticastMessage(rm);
+
+               Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " started flapping (" + Convert::ToString(GetFlappingThreshold()) + "% < " + Convert::ToString(GetFlappingCurrent()) + "%).");
        }
        else if (was_flapping && !is_flapping) {
                RequestNotifications(NotificationFlappingEnd, cr);
@@ -509,6 +519,8 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
                rm.SetParams(params);
 
                EndpointManager::GetInstance()->SendMulticastMessage(rm);
+
+               Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " stopped flapping (" + Convert::ToString(GetFlappingThreshold()) + "% >= " + Convert::ToString(GetFlappingCurrent()) + "%).");
        }
        else if (send_notification)
                RequestNotifications(recovery ? NotificationRecovery : NotificationProblem, cr);
index cdac8a3109436ff686f8c0dbfe68a8f864717af9..b3d5106c20bb57dcf336a57229685af86f633208 100644 (file)
@@ -38,6 +38,9 @@ double Service::GetFlappingCurrent(void) const
        if (m_FlappingNegative.IsEmpty() || m_FlappingPositive.IsEmpty())
                return 0;
 
+       if ((m_FlappingPositive + m_FlappingNegative) <= 0)
+               return 0;
+
        return 100 * m_FlappingPositive / (m_FlappingPositive + m_FlappingNegative);
 }