Implement override_check_period.

Refs #4746
This commit is contained in:
Gunnar Beutner 2013-11-26 13:43:56 +01:00
parent 245dd66bab
commit 6428fc6123
6 changed files with 75 additions and 1 deletions

View File

@ -197,6 +197,8 @@ void ExternalCommandProcessor::Initialize(void)
RegisterCommand("CHANGE_SVC_CHECK_COMMAND", &ExternalCommandProcessor::ChangeSvcCheckCommand);
RegisterCommand("CHANGE_MAX_HOST_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxHostCheckAttempts);
RegisterCommand("CHANGE_MAX_SVC_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxSvcCheckAttempts);
RegisterCommand("CHANGE_HOST_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeHostCheckTimeperiod);
RegisterCommand("CHANGE_SVC_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeSvcCheckTimeperiod);
}
void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandProcessor::Callback& callback)
@ -2167,3 +2169,53 @@ void ExternalCommandProcessor::ChangeMaxSvcCheckAttempts(double time, const std:
service->SetMaxCheckAttempts(attempts);
}
}
void ExternalCommandProcessor::ChangeHostCheckTimeperiod(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 check period for non-existent host '" + arguments[0] + "'"));
Service::Ptr hc = host->GetCheckService();
TimePeriod::Ptr tp = TimePeriod::GetByName(arguments[2]);
if (!tp)
BOOST_THROW_EXCEPTION(std::invalid_argument("Time period '" + arguments[1] + "' does not exist."));
Log(LogInformation, "icinga", "Changing check period for host '" + arguments[0] + "' to '" + arguments[1] + "'");
{
ObjectLock olock(hc);
hc->SetCheckPeriod(tp);
}
}
void ExternalCommandProcessor::ChangeSvcCheckTimeperiod(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 check period for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
TimePeriod::Ptr tp = TimePeriod::GetByName(arguments[2]);
if (!tp)
BOOST_THROW_EXCEPTION(std::invalid_argument("Time period '" + arguments[2] + "' does not exist."));
Log(LogInformation, "icinga", "Changing check period for service '" + arguments[1] + "' to '" + arguments[2] + "'");
{
ObjectLock olock(service);
service->SetCheckPeriod(tp);
}
}

View File

@ -147,6 +147,8 @@ private:
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);
static void ChangeHostCheckTimeperiod(double time, const std::vector<String>& arguments);
static void ChangeSvcCheckTimeperiod(double time, const std::vector<String>& arguments);
};
}

View File

@ -64,7 +64,19 @@ void Service::SetCheckCommand(const CheckCommand::Ptr& command)
TimePeriod::Ptr Service::GetCheckPeriod(void) const
{
return TimePeriod::GetByName(GetCheckPeriodRaw());
String tp;
if (!GetOverrideCheckPeriod().IsEmpty())
tp = GetOverrideCheckPeriod();
else
tp = GetCheckPeriodRaw();
return TimePeriod::GetByName(tp);
}
void Service::SetCheckPeriod(const TimePeriod::Ptr& tp)
{
SetOverrideCheckPeriod(tp->GetName());
}
double Service::GetCheckInterval(void) const

View File

@ -310,6 +310,9 @@ int Service::GetModifiedAttributes(void) const
if (!GetOverrideMaxCheckAttempts().IsEmpty())
attrs |= ModAttrMaxCheckAttempts;
if (!GetOverrideCheckPeriod().IsEmpty())
attrs |= ModAttrCheckTimeperiod;
// TODO: finish
return attrs;
@ -349,6 +352,9 @@ void Service::SetModifiedAttributes(int flags)
if ((flags & ModAttrMaxCheckAttempts) == 0)
SetOverrideMaxCheckAttempts(Empty);
if ((flags & ModAttrCheckTimeperiod) == 0)
SetOverrideCheckPeriod(Empty);
}
bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const

View File

@ -112,6 +112,7 @@ public:
void SetCheckCommand(const shared_ptr<CheckCommand>& command);
TimePeriod::Ptr GetCheckPeriod(void) const;
void SetCheckPeriod(const TimePeriod::Ptr& tp);
double GetCheckInterval(void) const;
void SetCheckInterval(double interval);

View File

@ -139,6 +139,7 @@ class Service : DynamicObject
[state] Value override_event_command;
[state] Value override_check_command;
[state] Value override_max_check_attempts;
[state] Value override_check_period;
};
}