mirror of https://github.com/Icinga/icinga2.git
Implement support for enabling/disabling passive checks.
This commit is contained in:
parent
3d0a3bb874
commit
335a0b3067
|
@ -72,7 +72,7 @@ void CheckerComponent::CheckTimerHandler(void)
|
|||
|
||||
/* reschedule the service if checks are currently disabled
|
||||
* for it and this is not a forced check */
|
||||
if (!service->GetEnableChecks()) {
|
||||
if (!service->GetEnableActiveChecks()) {
|
||||
if (!service->GetForceNextCheck()) {
|
||||
Logger::Write(LogDebug, "checker", "Ignoring service check for disabled service: " + service->GetName());
|
||||
|
||||
|
|
|
@ -294,8 +294,8 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, const Service::Ptr& servic
|
|||
<< "\t" << "last_state_change=" << service->GetLastStateChange() << "\n"
|
||||
<< "\t" << "last_hard_state_change=" << service->GetLastHardStateChange() << "\n"
|
||||
<< "\t" << "last_update=" << time(NULL) << "\n"
|
||||
<< "\t" << "active_checks_enabled=" << (service->GetEnableChecks() ? 1 : 0) <<"\n"
|
||||
<< "\t" << "passive_checks_enabled=1" << "\n"
|
||||
<< "\t" << "active_checks_enabled=" << (service->GetEnableActiveChecks() ? 1 : 0) <<"\n"
|
||||
<< "\t" << "passive_checks_enabled=" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\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"
|
||||
|
@ -312,8 +312,8 @@ void CompatComponent::DumpServiceObject(ofstream& fp, const Service::Ptr& servic
|
|||
<< "\t" << "check_interval" << "\t" << service->GetCheckInterval() / 60.0 << "\n"
|
||||
<< "\t" << "retry_interval" << "\t" << service->GetRetryInterval() / 60.0 << "\n"
|
||||
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
||||
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n"
|
||||
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "}" << "\n"
|
||||
<< "\n";
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ void DelegationComponent::DelegationTimerHandler(void)
|
|||
}
|
||||
|
||||
if (candidates.size() == 0) {
|
||||
if (service->GetState() != StateUncheckable && service->GetEnableChecks()) {
|
||||
if (service->GetState() != StateUncheckable && service->GetEnableActiveChecks()) {
|
||||
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
|
||||
|
||||
double now = Utility::GetTime();
|
||||
|
|
|
@ -45,6 +45,12 @@ void ExternalCommand::Execute(double time, const String& command, const vector<S
|
|||
RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::DisableHostgroupSvcChecks);
|
||||
RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommand::EnableServicegroupSvcChecks);
|
||||
RegisterCommand("DISABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommand::DisableServicegroupSvcChecks);
|
||||
RegisterCommand("ENABLE_PASSIVE_SVC_CHECKS", &ExternalCommand::EnablePassiveSvcChecks);
|
||||
RegisterCommand("DISABLE_PASSIVE_SVC_CHECKS", &ExternalCommand::DisablePassiveSvcChecks);
|
||||
RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommand::EnableServicegroupPassiveSvcChecks);
|
||||
RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommand::DisableServicegroupPassiveSvcChecks);
|
||||
RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommand::EnableHostgroupPassiveSvcChecks);
|
||||
RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommand::DisableHostgroupPassiveSvcChecks);
|
||||
|
||||
m_Initialized = true;
|
||||
}
|
||||
|
@ -78,6 +84,9 @@ void ExternalCommand::ProcessServiceCheckResult(double time, const vector<String
|
|||
|
||||
Service::Ptr service = Service::GetByName(arguments[1]);
|
||||
|
||||
if (!service->GetEnablePassiveChecks())
|
||||
throw_exception(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
|
||||
|
||||
int exitStatus = arguments[2].ToDouble();
|
||||
Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]);
|
||||
result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
|
||||
|
@ -139,8 +148,8 @@ void ExternalCommand::EnableSvcCheck(double time, const vector<String>& argument
|
|||
|
||||
Service::Ptr service = Service::GetByName(arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Enabling checks for service '" + arguments[1] + "'");
|
||||
service->SetEnableChecks(true);
|
||||
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + arguments[1] + "'");
|
||||
service->SetEnableActiveChecks(true);
|
||||
}
|
||||
|
||||
void ExternalCommand::DisableSvcCheck(double time, const vector<String>& arguments)
|
||||
|
@ -153,8 +162,8 @@ void ExternalCommand::DisableSvcCheck(double time, const vector<String>& argumen
|
|||
|
||||
Service::Ptr service = Service::GetByName(arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Disabling checks for service '" + arguments[1] + "'");
|
||||
service->SetEnableChecks(false);
|
||||
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + arguments[1] + "'");
|
||||
service->SetEnableActiveChecks(false);
|
||||
}
|
||||
|
||||
void ExternalCommand::ShutdownProcess(double time, const vector<String>& arguments)
|
||||
|
@ -235,8 +244,8 @@ void ExternalCommand::EnableHostSvcChecks(double time, const vector<String>& arg
|
|||
if (service->GetHost() != host)
|
||||
continue;
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Enabling checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableChecks(true);
|
||||
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableActiveChecks(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,8 +266,8 @@ void ExternalCommand::DisableHostSvcChecks(double time, const vector<String>& ar
|
|||
if (service->GetHost() != host)
|
||||
continue;
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Disabling checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableChecks(false);
|
||||
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableActiveChecks(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,8 +339,8 @@ void ExternalCommand::EnableHostgroupSvcChecks(double time, const vector<String>
|
|||
|
||||
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
||||
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
||||
Logger::Write(LogInformation, "icinga", "Enabling checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableChecks(true);
|
||||
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableActiveChecks(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -348,8 +357,8 @@ void ExternalCommand::DisableHostgroupSvcChecks(double time, const vector<String
|
|||
|
||||
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
||||
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
||||
Logger::Write(LogInformation, "icinga", "Disabling checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableChecks(false);
|
||||
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableActiveChecks(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -365,8 +374,8 @@ void ExternalCommand::EnableServicegroupSvcChecks(double time, const vector<Stri
|
|||
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
||||
Logger::Write(LogInformation, "icinga", "Enabling checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableChecks(true);
|
||||
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableActiveChecks(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -381,8 +390,103 @@ void ExternalCommand::DisableServicegroupSvcChecks(double time, const vector<Str
|
|||
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
||||
Logger::Write(LogInformation, "icinga", "Disabling checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableChecks(false);
|
||||
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
|
||||
service->SetEnableActiveChecks(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommand::EnablePassiveSvcChecks(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
throw_exception(invalid_argument("Expected 2 arguments."));
|
||||
|
||||
if (!Service::Exists(arguments[1]))
|
||||
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
||||
|
||||
Service::Ptr service = Service::GetByName(arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + arguments[1] + "'");
|
||||
service->SetEnablePassiveChecks(true);
|
||||
}
|
||||
|
||||
void ExternalCommand::DisablePassiveSvcChecks(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
throw_exception(invalid_argument("Expected 2 arguments."));
|
||||
|
||||
if (!Service::Exists(arguments[1]))
|
||||
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
||||
|
||||
Service::Ptr service = Service::GetByName(arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + arguments[1] + "'");
|
||||
service->SetEnablePassiveChecks(false);
|
||||
}
|
||||
|
||||
void ExternalCommand::EnableServicegroupPassiveSvcChecks(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 1)
|
||||
throw_exception(invalid_argument("Expected 1 argument."));
|
||||
|
||||
if (!ServiceGroup::Exists(arguments[0]))
|
||||
throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
|
||||
|
||||
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
||||
Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
|
||||
service->SetEnablePassiveChecks(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommand::DisableServicegroupPassiveSvcChecks(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 1)
|
||||
throw_exception(invalid_argument("Expected 1 argument."));
|
||||
|
||||
if (!ServiceGroup::Exists(arguments[0]))
|
||||
throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
|
||||
|
||||
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
||||
Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
|
||||
service->SetEnablePassiveChecks(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommand::EnableHostgroupPassiveSvcChecks(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 1)
|
||||
throw_exception(invalid_argument("Expected 1 argument."));
|
||||
|
||||
if (!HostGroup::Exists(arguments[0]))
|
||||
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
||||
|
||||
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
||||
|
||||
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
||||
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
||||
Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
|
||||
service->SetEnablePassiveChecks(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommand::DisableHostgroupPassiveSvcChecks(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 1)
|
||||
throw_exception(invalid_argument("Expected 1 argument."));
|
||||
|
||||
if (!HostGroup::Exists(arguments[0]))
|
||||
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
||||
|
||||
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
||||
|
||||
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
||||
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
||||
Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
|
||||
service->SetEnablePassiveChecks(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,12 @@ public:
|
|||
static void DisableHostgroupSvcChecks(double time, const vector<String>& arguments);
|
||||
static void EnableServicegroupSvcChecks(double time, const vector<String>& arguments);
|
||||
static void DisableServicegroupSvcChecks(double time, const vector<String>& arguments);
|
||||
static void EnablePassiveSvcChecks(double time, const vector<String>& arguments);
|
||||
static void DisablePassiveSvcChecks(double time, const vector<String>& arguments);
|
||||
static void EnableServicegroupPassiveSvcChecks(double time, const vector<String>& arguments);
|
||||
static void DisableServicegroupPassiveSvcChecks(double time, const vector<String>& arguments);
|
||||
static void EnableHostgroupPassiveSvcChecks(double time, const vector<String>& arguments);
|
||||
static void DisableHostgroupPassiveSvcChecks(double time, const vector<String>& arguments);
|
||||
|
||||
private:
|
||||
typedef function<void (double time, const vector<String>& arguments)> Callback;
|
||||
|
|
|
@ -43,7 +43,8 @@ static AttributeDescription serviceAttributes[] = {
|
|||
{ "last_result", Attribute_Replicated },
|
||||
{ "last_state_change", Attribute_Replicated },
|
||||
{ "last_hard_state_change", Attribute_Replicated },
|
||||
{ "enable_checks", Attribute_Replicated },
|
||||
{ "enable_active_checks", Attribute_Replicated },
|
||||
{ "enable_passive_checks", Attribute_Replicated },
|
||||
{ "force_next_check", Attribute_Replicated },
|
||||
{ "acknowledgement", Attribute_Replicated },
|
||||
{ "acknowledgement_expiry", Attribute_Replicated }
|
||||
|
@ -383,9 +384,9 @@ double Service::GetLastHardStateChange(void) const
|
|||
return value;
|
||||
}
|
||||
|
||||
bool Service::GetEnableChecks(void) const
|
||||
bool Service::GetEnableActiveChecks(void) const
|
||||
{
|
||||
Value value = Get("enable_checks");
|
||||
Value value = Get("enable_active_checks");
|
||||
|
||||
if (value.IsEmpty())
|
||||
return true;
|
||||
|
@ -393,9 +394,24 @@ bool Service::GetEnableChecks(void) const
|
|||
return static_cast<bool>(value);
|
||||
}
|
||||
|
||||
void Service::SetEnableChecks(bool enabled)
|
||||
void Service::SetEnablePassiveChecks(bool enabled)
|
||||
{
|
||||
Set("enable_checks", enabled ? 1 : 0);
|
||||
Set("enable_passive_checks", enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
bool Service::GetEnablePassiveChecks(void) const
|
||||
{
|
||||
Value value = Get("enable_passive_checks");
|
||||
|
||||
if (value.IsEmpty())
|
||||
return true;
|
||||
|
||||
return static_cast<bool>(value);
|
||||
}
|
||||
|
||||
void Service::SetEnableActiveChecks(bool enabled)
|
||||
{
|
||||
Set("enable_active_checks", enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
bool Service::GetForceNextCheck(void) const
|
||||
|
|
|
@ -132,8 +132,11 @@ public:
|
|||
void SetLastHardStateChange(double ts);
|
||||
double GetLastHardStateChange(void) const;
|
||||
|
||||
bool GetEnableChecks(void) const;
|
||||
void SetEnableChecks(bool enabled);
|
||||
bool GetEnableActiveChecks(void) const;
|
||||
void SetEnableActiveChecks(bool enabled);
|
||||
|
||||
bool GetEnablePassiveChecks(void) const;
|
||||
void SetEnablePassiveChecks(bool enabled);
|
||||
|
||||
bool GetForceNextCheck(void) const;
|
||||
void SetForceNextCheck(bool forced);
|
||||
|
|
Loading…
Reference in New Issue