From d07dc47b1b7524bd0d8ad07d10846851159e935e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 16 Oct 2013 12:08:36 +0200 Subject: [PATCH] Implement CHANGE_HOST_MODATTR. --- lib/icinga/externalcommandprocessor.cpp | 23 +++++++++++++++++++++++ lib/icinga/externalcommandprocessor.h | 1 + 2 files changed, 24 insertions(+) diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 5abdfa1fc..e447a1660 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -181,6 +181,7 @@ void ExternalCommandProcessor::Initialize(void) RegisterCommand("START_EXECUTING_SVC_CHECKS", &ExternalCommandProcessor::StartExecutingSvcChecks); RegisterCommand("STOP_EXECUTING_SVC_CHECKS", &ExternalCommandProcessor::StopExecutingSvcChecks); RegisterCommand("CHANGE_SVC_MODATTR", &ExternalCommandProcessor::ChangeSvcModAttr); + RegisterCommand("CHANGE_HOST_MODATTR", &ExternalCommandProcessor::ChangeHostModAttr); } void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandProcessor::Callback& callback) @@ -1836,4 +1837,26 @@ void ExternalCommandProcessor::ChangeSvcModAttr(double time, const std::vectorSetModifiedAttributes(modifiedAttributes); } +} + +void ExternalCommandProcessor::ChangeHostModAttr(double time, const std::vector& arguments) +{ + if (arguments.size() < 3) + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments.")); + + Host::Ptr host = Host::GetByName(arguments[0]); + + if (!host) + BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update modified attributes for non-existent host '" + arguments[0] + "'")); + + Log(LogInformation, "icinga", "Updating modified attributes for for host '" + arguments[0] + "'"); + Service::Ptr hc = host->GetCheckService(); + + int modifiedAttributes = Convert::ToLong(arguments[2]); + + { + ObjectLock olock(service); + + hc->SetModifiedAttributes(modifiedAttributes); + } } \ No newline at end of file diff --git a/lib/icinga/externalcommandprocessor.h b/lib/icinga/externalcommandprocessor.h index 03e9fd303..f8cf9b94c 100644 --- a/lib/icinga/externalcommandprocessor.h +++ b/lib/icinga/externalcommandprocessor.h @@ -132,6 +132,7 @@ private: static void StartExecutingSvcChecks(double time, const std::vector& arguments); static void StopExecutingSvcChecks(double time, const std::vector& arguments); static void ChangeSvcModAttr(double time, const std::vector& arguments); + static void ChangeHostModAttr(double time, const std::vector& arguments); }; }