mirror of https://github.com/Icinga/icinga2.git
parent
f694954512
commit
71ec1d2b95
|
@ -70,6 +70,20 @@ void CheckerComponent::CheckTimerHandler(void)
|
||||||
|
|
||||||
idx.erase(it);
|
idx.erase(it);
|
||||||
|
|
||||||
|
/* reschedule the service if checks are currently disabled
|
||||||
|
* for it and this is not a forced check */
|
||||||
|
if (!service->GetEnableChecks()) {
|
||||||
|
if (!service->GetForceNextCheck()) {
|
||||||
|
service->UpdateNextCheck();
|
||||||
|
|
||||||
|
idx.insert(service);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
service->SetForceNextCheck(false);
|
||||||
|
}
|
||||||
|
|
||||||
Dictionary::Ptr cr = service->GetLastCheckResult();
|
Dictionary::Ptr cr = service->GetLastCheckResult();
|
||||||
|
|
||||||
if (cr) {
|
if (cr) {
|
||||||
|
|
|
@ -285,7 +285,7 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, const Service::Ptr& servic
|
||||||
<< "\t" << "last_state_change=" << service->GetLastStateChange() << "\n"
|
<< "\t" << "last_state_change=" << service->GetLastStateChange() << "\n"
|
||||||
<< "\t" << "last_hard_state_change=" << service->GetLastHardStateChange() << "\n"
|
<< "\t" << "last_hard_state_change=" << service->GetLastHardStateChange() << "\n"
|
||||||
<< "\t" << "last_update=" << time(NULL) << "\n"
|
<< "\t" << "last_update=" << time(NULL) << "\n"
|
||||||
<< "\t" << "active_checks_enabled=1" << "\n"
|
<< "\t" << "active_checks_enabled=" << (service->GetEnableChecks() ? 1 : 0) <<"\n"
|
||||||
<< "\t" << "passive_checks_enabled=1" << "\n"
|
<< "\t" << "passive_checks_enabled=1" << "\n"
|
||||||
<< "\t" << "}" << "\n"
|
<< "\t" << "}" << "\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
@ -300,7 +300,7 @@ void CompatComponent::DumpServiceObject(ofstream& fp, const Service::Ptr& servic
|
||||||
<< "\t" << "check_interval" << "\t" << service->GetCheckInterval() / 60.0 << "\n"
|
<< "\t" << "check_interval" << "\t" << service->GetCheckInterval() / 60.0 << "\n"
|
||||||
<< "\t" << "retry_interval" << "\t" << service->GetRetryInterval() / 60.0 << "\n"
|
<< "\t" << "retry_interval" << "\t" << service->GetRetryInterval() / 60.0 << "\n"
|
||||||
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
||||||
<< "\t" << "active_checks_enabled" << "\t" << 1 << "\n"
|
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableChecks() ? 1 : 0) << "\n"
|
||||||
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n"
|
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n"
|
||||||
<< "\t" << "}" << "\n"
|
<< "\t" << "}" << "\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
|
@ -614,6 +614,12 @@ Attribute: checkers
|
||||||
Optional. A list of remote endpoints that may check this service. Wildcards can
|
Optional. A list of remote endpoints that may check this service. Wildcards can
|
||||||
be used here.
|
be used here.
|
||||||
|
|
||||||
|
Attribute: enable_checks
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Optional. Whether active checks should be performed for this service. Defaults
|
||||||
|
to 1 (true).
|
||||||
|
|
||||||
Type: ServiceGroup
|
Type: ServiceGroup
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -747,6 +753,12 @@ Attribute: checkers
|
||||||
Optional. Copied into inline service definitions. The host itself does not have
|
Optional. Copied into inline service definitions. The host itself does not have
|
||||||
any checks.
|
any checks.
|
||||||
|
|
||||||
|
Attribute: enable_checks
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Optional. Copied into inline service definitions. The host itself does not have
|
||||||
|
any checks.
|
||||||
|
|
||||||
Type: HostGroup
|
Type: HostGroup
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ void ExternalCommand::Execute(double time, const String& command, const vector<S
|
||||||
RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommand::ProcessServiceCheckResult);
|
RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommand::ProcessServiceCheckResult);
|
||||||
RegisterCommand("SCHEDULE_SVC_CHECK", &ExternalCommand::ScheduleSvcCheck);
|
RegisterCommand("SCHEDULE_SVC_CHECK", &ExternalCommand::ScheduleSvcCheck);
|
||||||
RegisterCommand("SCHEDULE_FORCED_SVC_CHECK", &ExternalCommand::ScheduleForcedSvcCheck);
|
RegisterCommand("SCHEDULE_FORCED_SVC_CHECK", &ExternalCommand::ScheduleForcedSvcCheck);
|
||||||
|
RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommand::EnableSvcCheck);
|
||||||
|
RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommand::DisableSvcCheck);
|
||||||
|
|
||||||
m_Initialized = true;
|
m_Initialized = true;
|
||||||
}
|
}
|
||||||
|
@ -110,9 +112,36 @@ void ExternalCommand::ScheduleForcedSvcCheck(double time, const vector<String>&
|
||||||
|
|
||||||
Service::Ptr service = Service::GetByName(arguments[1]);
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
||||||
|
|
||||||
// TODO: force checks (once we have time periods)
|
|
||||||
|
|
||||||
Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
|
Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
|
||||||
|
service->SetForceNextCheck(true);
|
||||||
service->SetNextCheck(arguments[2].ToDouble());
|
service->SetNextCheck(arguments[2].ToDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExternalCommand::EnableSvcCheck(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 checks for service '" + arguments[1] + "'");
|
||||||
|
service->SetEnableChecks(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExternalCommand::DisableSvcCheck(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 checks for service '" + arguments[1] + "'");
|
||||||
|
service->SetEnableChecks(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ public:
|
||||||
static void ProcessServiceCheckResult(double time, const vector<String>& arguments);
|
static void ProcessServiceCheckResult(double time, const vector<String>& arguments);
|
||||||
static void ScheduleSvcCheck(double time, const vector<String>& arguments);
|
static void ScheduleSvcCheck(double time, const vector<String>& arguments);
|
||||||
static void ScheduleForcedSvcCheck(double time, const vector<String>& arguments);
|
static void ScheduleForcedSvcCheck(double time, const vector<String>& arguments);
|
||||||
|
static void EnableSvcCheck(double time, const vector<String>& arguments);
|
||||||
|
static void DisableSvcCheck(double time, const vector<String>& arguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef function<void (double time, const vector<String>& arguments)> Callback;
|
typedef function<void (double time, const vector<String>& arguments)> Callback;
|
||||||
|
|
|
@ -175,6 +175,10 @@ static void CopyServiceAttributes(const Host::Ptr& host, TDict serviceDesc,
|
||||||
if (!hostchecks.IsEmpty())
|
if (!hostchecks.IsEmpty())
|
||||||
builder->AddExpression("dependencies", OperatorPlus,
|
builder->AddExpression("dependencies", OperatorPlus,
|
||||||
Service::ResolveDependencies(host, hostchecks));
|
Service::ResolveDependencies(host, hostchecks));
|
||||||
|
|
||||||
|
Value enableChecks = serviceDesc->Get("enable_checks");
|
||||||
|
if (!enableChecks.IsEmpty())
|
||||||
|
builder->AddExpression("enable_checks", OperatorSet, enableChecks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::ObjectCommittedHandler(const ConfigItem::Ptr& item)
|
void Host::ObjectCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
|
|
|
@ -41,7 +41,9 @@ static AttributeDescription serviceAttributes[] = {
|
||||||
{ "state_type", Attribute_Replicated },
|
{ "state_type", Attribute_Replicated },
|
||||||
{ "last_result", Attribute_Replicated },
|
{ "last_result", Attribute_Replicated },
|
||||||
{ "last_state_change", Attribute_Replicated },
|
{ "last_state_change", Attribute_Replicated },
|
||||||
{ "last_hard_state_change", Attribute_Replicated }
|
{ "last_hard_state_change", Attribute_Replicated },
|
||||||
|
{ "enable_checks", Attribute_Replicated },
|
||||||
|
{ "force_next_check", Attribute_Replicated }
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TYPE(Service, serviceAttributes);
|
REGISTER_TYPE(Service, serviceAttributes);
|
||||||
|
@ -353,6 +355,36 @@ double Service::GetLastHardStateChange(void) const
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Service::GetEnableChecks(void) const
|
||||||
|
{
|
||||||
|
Value value = Get("enable_checks");
|
||||||
|
|
||||||
|
if (value.IsEmpty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return static_cast<bool>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Service::SetEnableChecks(bool enabled)
|
||||||
|
{
|
||||||
|
Set("enable_checks", enabled ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Service::GetForceNextCheck(void) const
|
||||||
|
{
|
||||||
|
Value value = Get("force_next_check");
|
||||||
|
|
||||||
|
if (value.IsEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return static_cast<bool>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Service::SetForceNextCheck(bool forced)
|
||||||
|
{
|
||||||
|
Set("force_next_check", forced ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
void Service::ApplyCheckResult(const Dictionary::Ptr& cr)
|
void Service::ApplyCheckResult(const Dictionary::Ptr& cr)
|
||||||
{
|
{
|
||||||
ServiceState old_state = GetState();
|
ServiceState old_state = GetState();
|
||||||
|
|
|
@ -116,6 +116,12 @@ public:
|
||||||
void SetLastHardStateChange(double ts);
|
void SetLastHardStateChange(double ts);
|
||||||
double GetLastHardStateChange(void) const;
|
double GetLastHardStateChange(void) const;
|
||||||
|
|
||||||
|
bool GetEnableChecks(void) const;
|
||||||
|
void SetEnableChecks(bool enabled);
|
||||||
|
|
||||||
|
bool GetForceNextCheck(void) const;
|
||||||
|
void SetForceNextCheck(bool forced);
|
||||||
|
|
||||||
void ApplyCheckResult(const Dictionary::Ptr& cr);
|
void ApplyCheckResult(const Dictionary::Ptr& cr);
|
||||||
|
|
||||||
void BeginExecuteCheck(const function<void (void)>& callback);
|
void BeginExecuteCheck(const function<void (void)>& callback);
|
||||||
|
|
Loading…
Reference in New Issue