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();
if (cr) {
<< "\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=1" << "\n"
+ << "\t" << "active_checks_enabled=" << (service->GetEnableChecks() ? 1 : 0) <<"\n"
<< "\t" << "passive_checks_enabled=1" << "\n"
<< "\t" << "}" << "\n"
<< "\n";
<< "\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" << 1 << "\n"
+ << "\t" << "active_checks_enabled" << "\t" << (service->GetEnableChecks() ? 1 : 0) << "\n"
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n"
<< "\t" << "}" << "\n"
<< "\n";
Optional. A list of remote endpoints that may check this service. Wildcards can
be used here.
+Attribute: enable_checks
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Optional. Whether active checks should be performed for this service. Defaults
+to 1 (true).
+
Type: ServiceGroup
~~~~~~~~~~~~~~~~~~
Optional. Copied into inline service definitions. The host itself does not have
any checks.
+Attribute: enable_checks
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Optional. Copied into inline service definitions. The host itself does not have
+any checks.
+
Type: HostGroup
~~~~~~~~~~~~~~~
RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommand::ProcessServiceCheckResult);
RegisterCommand("SCHEDULE_SVC_CHECK", &ExternalCommand::ScheduleSvcCheck);
RegisterCommand("SCHEDULE_FORCED_SVC_CHECK", &ExternalCommand::ScheduleForcedSvcCheck);
+ RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommand::EnableSvcCheck);
+ RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommand::DisableSvcCheck);
m_Initialized = true;
}
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] + "'");
+ service->SetForceNextCheck(true);
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);
+}
+
static void ProcessServiceCheckResult(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 EnableSvcCheck(double time, const vector<String>& arguments);
+ static void DisableSvcCheck(double time, const vector<String>& arguments);
private:
typedef function<void (double time, const vector<String>& arguments)> Callback;
if (!hostchecks.IsEmpty())
builder->AddExpression("dependencies", OperatorPlus,
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)
{ "state_type", Attribute_Replicated },
{ "last_result", 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);
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)
{
ServiceState old_state = GetState();
void SetLastHardStateChange(double ts);
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 BeginExecuteCheck(const function<void (void)>& callback);