mirror of https://github.com/Icinga/icinga2.git
parent
1c8fb7a198
commit
245dd66bab
|
@ -195,6 +195,8 @@ void ExternalCommandProcessor::Initialize(void)
|
|||
RegisterCommand("CHANGE_SVC_EVENT_HANDLER", &ExternalCommandProcessor::ChangeSvcEventHandler);
|
||||
RegisterCommand("CHANGE_HOST_CHECK_COMMAND", &ExternalCommandProcessor::ChangeHostCheckCommand);
|
||||
RegisterCommand("CHANGE_SVC_CHECK_COMMAND", &ExternalCommandProcessor::ChangeSvcCheckCommand);
|
||||
RegisterCommand("CHANGE_MAX_HOST_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxHostCheckAttempts);
|
||||
RegisterCommand("CHANGE_MAX_SVC_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxSvcCheckAttempts);
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandProcessor::Callback& callback)
|
||||
|
@ -2121,3 +2123,47 @@ void ExternalCommandProcessor::ChangeSvcCheckCommand(double time, const std::vec
|
|||
service->SetCheckCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::ChangeMaxHostCheckAttempts(double time, const std::vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
|
||||
|
||||
Host::Ptr host = Host::GetByName(arguments[0]);
|
||||
|
||||
if (!host)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for non-existent host '" + arguments[0] + "'"));
|
||||
|
||||
Service::Ptr hc = host->GetCheckService();
|
||||
|
||||
int attempts = Convert::ToLong(arguments[2]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing max check attempts for host '" + arguments[0] + "' to '" + arguments[1] + "'");
|
||||
|
||||
{
|
||||
ObjectLock olock(hc);
|
||||
|
||||
hc->SetMaxCheckAttempts(attempts);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::ChangeMaxSvcCheckAttempts(double time, const std::vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
|
||||
|
||||
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
|
||||
|
||||
if (!service)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
|
||||
|
||||
int attempts = Convert::ToLong(arguments[2]);
|
||||
|
||||
Log(LogInformation, "icinga", "Changing max check attempts for service '" + arguments[1] + "' to '" + arguments[2] + "'");
|
||||
|
||||
{
|
||||
ObjectLock olock(service);
|
||||
|
||||
service->SetMaxCheckAttempts(attempts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,6 +145,8 @@ private:
|
|||
static void ChangeSvcEventHandler(double time, const std::vector<String>& arguments);
|
||||
static void ChangeHostCheckCommand(double time, const std::vector<String>& arguments);
|
||||
static void ChangeSvcCheckCommand(double time, const std::vector<String>& arguments);
|
||||
static void ChangeMaxHostCheckAttempts(double time, const std::vector<String>& arguments);
|
||||
static void ChangeMaxSvcCheckAttempts(double time, const std::vector<String>& arguments);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -193,6 +193,19 @@ void Service::SetForceNextCheck(bool forced, const String& authority)
|
|||
OnForceNextCheckChanged(GetSelf(), forced, authority);
|
||||
}
|
||||
|
||||
int Service::GetMaxCheckAttempts(void) const
|
||||
{
|
||||
if (!GetOverrideMaxCheckAttempts().IsEmpty())
|
||||
return GetOverrideMaxCheckAttempts();
|
||||
else
|
||||
return GetMaxCheckAttemptsRaw();
|
||||
}
|
||||
|
||||
void Service::SetMaxCheckAttempts(int attempts)
|
||||
{
|
||||
SetOverrideMaxCheckAttempts(attempts);
|
||||
}
|
||||
|
||||
void Service::ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority)
|
||||
{
|
||||
double now = Utility::GetTime();
|
||||
|
|
|
@ -307,6 +307,9 @@ int Service::GetModifiedAttributes(void) const
|
|||
if (!GetOverrideCheckCommand().IsEmpty())
|
||||
attrs |= ModAttrCheckCommand;
|
||||
|
||||
if (!GetOverrideMaxCheckAttempts().IsEmpty())
|
||||
attrs |= ModAttrMaxCheckAttempts;
|
||||
|
||||
// TODO: finish
|
||||
|
||||
return attrs;
|
||||
|
@ -343,6 +346,9 @@ void Service::SetModifiedAttributes(int flags)
|
|||
|
||||
if ((flags & ModAttrCheckCommand) == 0)
|
||||
SetOverrideCheckCommand(Empty);
|
||||
|
||||
if ((flags & ModAttrMaxCheckAttempts) == 0)
|
||||
SetOverrideMaxCheckAttempts(Empty);
|
||||
}
|
||||
|
||||
bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const
|
||||
|
|
|
@ -119,6 +119,9 @@ public:
|
|||
double GetRetryInterval(void) const;
|
||||
void SetRetryInterval(double interval);
|
||||
|
||||
int GetMaxCheckAttempts(void) const;
|
||||
void SetMaxCheckAttempts(int attempts);
|
||||
|
||||
long GetSchedulingOffset(void);
|
||||
void SetSchedulingOffset(long offset);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class Service : DynamicObject
|
|||
[config] Array::Ptr service_dependencies;
|
||||
[config] Array::Ptr groups;
|
||||
[config, protected] String check_command (CheckCommandRaw);
|
||||
[config] int max_check_attempts {
|
||||
[config] int max_check_attempts (MaxCheckAttemptsRaw) {
|
||||
default {{{ return 3; }}}
|
||||
};
|
||||
[config, protected] String check_period (CheckPeriodRaw);
|
||||
|
@ -138,6 +138,7 @@ class Service : DynamicObject
|
|||
[state] Value override_enable_event_handler;
|
||||
[state] Value override_event_command;
|
||||
[state] Value override_check_command;
|
||||
[state] Value override_max_check_attempts;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue