[icinga-checkins] icinga.org: icinga2/master: Implement the external commands " SCHEDULE_FORCED_HOST_SVC_CHECKS" and "SCHEDULE_HOST_SVC_CHECKS".

git at icinga.org git at icinga.org
Wed Jan 23 10:54:41 CET 2013


Module: icinga2
Branch: master
Commit: e6e0d69e43ade593f6e904ecca8760b04f76a331
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=e6e0d69e43ade593f6e904ecca8760b04f76a331

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Jan 23 10:42:16 2013 +0100

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(+), 0 deletions(-)

diff --git a/lib/icinga/externalcommand.cpp b/lib/icinga/externalcommand.cpp
index 56d3d23..aee5c9c 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<S
 		RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommand::EnableSvcCheck);
 		RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommand::DisableSvcCheck);
 		RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommand::ShutdownProcess);
+		RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommand::ScheduleForcedHostSvcChecks);
+		RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommand::ScheduleHostSvcChecks);
 
 		m_Initialized = true;
 	}
@@ -152,3 +154,58 @@ void ExternalCommand::ShutdownProcess(double time, const vector<String>& argumen
 	Application::RequestShutdown();
 }
 
+void ExternalCommand::ScheduleForcedHostSvcChecks(double time, const vector<String>& 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<Service>(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<String>& 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<Service>(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 4881ed1..bbeb598 100644
--- a/lib/icinga/externalcommand.h
+++ b/lib/icinga/externalcommand.h
@@ -35,6 +35,8 @@ public:
 	static void EnableSvcCheck(double time, const vector<String>& arguments);
 	static void DisableSvcCheck(double time, const vector<String>& arguments);
 	static void ShutdownProcess(double time, const vector<String>& arguments);
+	static void ScheduleForcedHostSvcChecks(double time, const vector<String>& arguments);
+	static void ScheduleHostSvcChecks(double time, const vector<String>& arguments);
 
 private:
 	typedef function<void (double time, const vector<String>& arguments)> Callback;





More information about the icinga-checkins mailing list