mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 07:04:37 +02:00
Implement external commands for flapping detection.
This commit is contained in:
parent
69fcd7fa40
commit
6f158ff793
@ -520,7 +520,7 @@ void CompatComponent::StatusTimerHandler(void)
|
|||||||
<< "\t" << "check_service_freshness=0" << "\n"
|
<< "\t" << "check_service_freshness=0" << "\n"
|
||||||
<< "\t" << "check_host_freshness=0" << "\n"
|
<< "\t" << "check_host_freshness=0" << "\n"
|
||||||
<< "\t" << "enable_notifications=1" << "\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" << "enable_failure_prediction=0" << "\n"
|
||||||
<< "\t" << "active_scheduled_service_check_stats=" << CIB::GetActiveChecksStatistics(60) << "," << CIB::GetActiveChecksStatistics(5 * 60) << "," << CIB::GetActiveChecksStatistics(15 * 60) << "\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"
|
<< "\t" << "passive_service_check_stats=" << CIB::GetPassiveChecksStatistics(60) << "," << CIB::GetPassiveChecksStatistics(5 * 60) << "," << CIB::GetPassiveChecksStatistics(15 * 60) << "\n"
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -113,6 +113,10 @@ private:
|
|||||||
static void EnableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments);
|
static void EnableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments);
|
||||||
static void EnableServicegroupHostChecks(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 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,21 @@ using namespace icinga;
|
|||||||
|
|
||||||
#define FLAPPING_INTERVAL (30 * 60)
|
#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)
|
void Service::UpdateFlappingStatus(bool stateChange)
|
||||||
{
|
{
|
||||||
double ts, now;
|
double ts, now;
|
||||||
|
@ -86,6 +86,7 @@ Service::Service(const Dictionary::Ptr& serializedObject)
|
|||||||
RegisterAttribute("flapping_counter", Attribute_Replicated, &m_FlappingCounter);
|
RegisterAttribute("flapping_counter", Attribute_Replicated, &m_FlappingCounter);
|
||||||
RegisterAttribute("flapping_lastchange", Attribute_Replicated, &m_FlappingLastChange);
|
RegisterAttribute("flapping_lastchange", Attribute_Replicated, &m_FlappingLastChange);
|
||||||
RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold);
|
RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold);
|
||||||
|
RegisterAttribute("enable_flapping", Attribute_Config, &m_EnableFlapping);
|
||||||
|
|
||||||
SetSchedulingOffset(rand());
|
SetSchedulingOffset(rand());
|
||||||
}
|
}
|
||||||
|
@ -249,6 +249,9 @@ public:
|
|||||||
shared_ptr<EventCommand> GetEventCommand(void) const;
|
shared_ptr<EventCommand> GetEventCommand(void) const;
|
||||||
|
|
||||||
/* Flapping Detection */
|
/* Flapping Detection */
|
||||||
|
bool GetEnableFlapping(void) const;
|
||||||
|
void SetEnableFlapping(bool enabled);
|
||||||
|
|
||||||
bool IsFlapping(void) const;
|
bool IsFlapping(void) const;
|
||||||
void UpdateFlappingStatus(bool stateChange);
|
void UpdateFlappingStatus(bool stateChange);
|
||||||
|
|
||||||
@ -325,6 +328,7 @@ private:
|
|||||||
Attribute<String> m_EventCommand;
|
Attribute<String> m_EventCommand;
|
||||||
|
|
||||||
/* Flapping */
|
/* Flapping */
|
||||||
|
Attribute<bool> m_EnableFlapping;
|
||||||
Attribute<long> m_FlappingCounter;
|
Attribute<long> m_FlappingCounter;
|
||||||
Attribute<double> m_FlappingLastChange;
|
Attribute<double> m_FlappingLastChange;
|
||||||
Attribute<double> m_FlappingThreshold;
|
Attribute<double> m_FlappingThreshold;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user