From e6e0d69e43ade593f6e904ecca8760b04f76a331 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 23 Jan 2013 10:42:16 +0100 Subject: [PATCH] Implement the external commands "SCHEDULE_FORCED_HOST_SVC_CHECKS" and "SCHEDULE_HOST_SVC_CHECKS". --- lib/icinga/externalcommand.cpp | 57 ++++++++++++++++++++++++++++++++++ lib/icinga/externalcommand.h | 2 ++ 2 files changed, 59 insertions(+) diff --git a/lib/icinga/externalcommand.cpp b/lib/icinga/externalcommand.cpp index 56d3d232d..aee5c9ca4 100644 --- a/lib/icinga/externalcommand.cpp +++ b/lib/icinga/externalcommand.cpp @@ -34,6 +34,8 @@ void ExternalCommand::Execute(double time, const String& command, const vector& argumen Application::RequestShutdown(); } +void ExternalCommand::ScheduleForcedHostSvcChecks(double time, const vector& arguments) +{ + if (arguments.size() < 2) + throw_exception(invalid_argument("Expected 2 arguments.")); + + if (!Host::Exists(arguments[0])) + throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + + double planned_check = arguments[1].ToDouble(); + + 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", "Rescheduling next check for service '" + service->GetName() + "'"); + service->SetNextCheck(planned_check); + service->SetForceNextCheck(true); + } +} + +void ExternalCommand::ScheduleHostSvcChecks(double time, const vector& arguments) +{ + if (arguments.size() < 2) + throw_exception(invalid_argument("Expected 2 arguments.")); + + if (!Host::Exists(arguments[0])) + throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + + double planned_check = arguments[1].ToDouble(); + + 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; + + if (planned_check > service->GetNextCheck()) { + Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" + + arguments[1] + "' (next check is already sooner than requested check time)"); + return; + } + + Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'"); + service->SetNextCheck(planned_check); + } +} + diff --git a/lib/icinga/externalcommand.h b/lib/icinga/externalcommand.h index 4881ed143..bbeb598dd 100644 --- a/lib/icinga/externalcommand.h +++ b/lib/icinga/externalcommand.h @@ -35,6 +35,8 @@ public: static void EnableSvcCheck(double time, const vector& arguments); static void DisableSvcCheck(double time, const vector& arguments); static void ShutdownProcess(double time, const vector& arguments); + static void ScheduleForcedHostSvcChecks(double time, const vector& arguments); + static void ScheduleHostSvcChecks(double time, const vector& arguments); private: typedef function& arguments)> Callback; -- 2.40.0