From bccb7ef61535405476fa93f6f97752d28c6c5c83 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 23 Jan 2013 10:51:54 +0100 Subject: [PATCH] Implemented the external commands "ENABLE_HOST_SVC_CHECKS" and "DISABLE_HOST_SVC_CHECKS". --- lib/icinga/externalcommand.cpp | 46 ++++++++++++++++++++++++++++++++++ lib/icinga/externalcommand.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/lib/icinga/externalcommand.cpp b/lib/icinga/externalcommand.cpp index aee5c9ca4..8c4764d34 100644 --- a/lib/icinga/externalcommand.cpp +++ b/lib/icinga/externalcommand.cpp @@ -36,6 +36,8 @@ void ExternalCommand::Execute(double time, const String& command, const vector& a } } +void ExternalCommand::EnableHostSvcChecks(double time, const vector& arguments) +{ + if (arguments.size() < 1) + throw_exception(invalid_argument("Expected 1 argument.")); + + if (!Host::Exists(arguments[0])) + throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + + Host::Ptr host = Host::GetByName(arguments[0]); + + DynamicObject::Ptr object; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) { + Service::Ptr service = static_pointer_cast(object); + + if (service->GetHost() != host) + continue; + + Logger::Write(LogInformation, "icinga", "Enabling checks for service '" + service->GetName() + "'"); + service->SetEnableChecks(true); + } +} + +void ExternalCommand::DisableHostSvcChecks(double time, const vector& arguments) +{ + if (arguments.size() < 1) + throw_exception(invalid_argument("Expected 1 arguments.")); + + if (!Host::Exists(arguments[0])) + throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + + Host::Ptr host = Host::GetByName(arguments[0]); + + DynamicObject::Ptr object; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) { + Service::Ptr service = static_pointer_cast(object); + + if (service->GetHost() != host) + continue; + + Logger::Write(LogInformation, "icinga", "Disabling checks for service '" + service->GetName() + "'"); + service->SetEnableChecks(false); + } +} + diff --git a/lib/icinga/externalcommand.h b/lib/icinga/externalcommand.h index bbeb598dd..adb7eb555 100644 --- a/lib/icinga/externalcommand.h +++ b/lib/icinga/externalcommand.h @@ -37,6 +37,8 @@ public: static void ShutdownProcess(double time, const vector& arguments); static void ScheduleForcedHostSvcChecks(double time, const vector& arguments); static void ScheduleHostSvcChecks(double time, const vector& arguments); + static void EnableHostSvcChecks(double time, const vector& arguments); + static void DisableHostSvcChecks(double time, const vector& arguments); private: typedef function& arguments)> Callback; -- 2.50.1