[icinga-checkins] icinga.org: icinga2/master: Add SCHEDULE_AND_PROPAGATE{, _TRIGGERED}_HOST_DOWNTIME external commands

git at icinga.org git at icinga.org
Wed Nov 2 09:54:46 CET 2016


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu Jul 21 17:01:49 2016 +0200

Add SCHEDULE_AND_PROPAGATE{,_TRIGGERED}_HOST_DOWNTIME external commands

refs #10896
refs #10897

---

 doc/22-migrating-from-icinga-1x.md      |    2 -
 doc/23-appendix.md                      |    2 +
 lib/icinga/externalcommandprocessor.cpp |   74 +++++++++++++++++++++++++++++++
 lib/icinga/externalcommandprocessor.hpp |    2 +
 4 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/doc/22-migrating-from-icinga-1x.md b/doc/22-migrating-from-icinga-1x.md
index 36f889a..6716f5a 100644
--- a/doc/22-migrating-from-icinga-1x.md
+++ b/doc/22-migrating-from-icinga-1x.md
@@ -1137,8 +1137,6 @@ The following external commands are not supported:
     ENABLE_SERVICE_FRESHNESS_CHECKS
     READ_STATE_INFORMATION
     SAVE_STATE_INFORMATION
-    SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME
-    SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME
     SET_HOST_NOTIFICATION_NUMBER
     SET_SVC_NOTIFICATION_NUMBER
     START_ACCEPTING_PASSIVE_HOST_CHECKS
diff --git a/doc/23-appendix.md b/doc/23-appendix.md
index 2286fb8..6a0e61b 100644
--- a/doc/23-appendix.md
+++ b/doc/23-appendix.md
@@ -47,6 +47,8 @@ Additional details can be found in the [Icinga 1.x Documentation](http://docs.ic
   PROCESS_FILE                              | ;<file_name>;<delete> (2)  | -
   SCHEDULE_SVC_DOWNTIME                     | ;<host_name>;<service_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (9)  | -
   DEL_SVC_DOWNTIME                          | ;<downtime_id> (1)   | -
+  SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME      | ;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8)  | -
+  SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME | ;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8)  | -
   SCHEDULE_HOST_DOWNTIME                    | ;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8)  | -
   DEL_HOST_DOWNTIME                         | ;<downtime_id> (1)  | -
   DEL_DOWNTIME_BY_HOST_NAME                 | ;<host_name>[;<service_name;>[;<start_time;>[;<comment_text;>]]] (1)  | -
diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp
index 9a67c0b..68b24b0 100644
--- a/lib/icinga/externalcommandprocessor.cpp
+++ b/lib/icinga/externalcommandprocessor.cpp
@@ -193,6 +193,8 @@ void ExternalCommandProcessor::StaticInitialize(void)
 	RegisterCommand("SCHEDULE_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleSvcDowntime, 9);
 	RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime, 1);
 	RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime, 8);
+	RegisterCommand("SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleAndPropagateHostDowntime, 8);
+	RegisterCommand("SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime, 8);
 	RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime, 1);
 	RegisterCommand("DEL_DOWNTIME_BY_HOST_NAME", &ExternalCommandProcessor::DelDowntimeByHostName, 1, 4);
 	RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime, 8);
@@ -1001,6 +1003,78 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<St
 	    Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
 }
 
+void ExternalCommandProcessor::ScheduleAndPropagateHostDowntime(double, const std::vector<String>& arguments)
+{
+	Host::Ptr host = Host::GetByName(arguments[0]);
+
+	if (!host)
+		BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule and propagate host downtime for non-existent host '" + arguments[0] + "'"));
+
+	String triggeredBy;
+	int triggeredByLegacy = Convert::ToLong(arguments[4]);
+	int is_fixed = Convert::ToLong(arguments[3]);
+	if (triggeredByLegacy != 0)
+		triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
+
+	Log(LogNotice, "ExternalCommandProcessor")
+	    << "Creating downtime for host " << host->GetName();
+
+	(void) Downtime::AddDowntime(host, arguments[6], arguments[7],
+	    Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+	    Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
+
+	/* Schedule downtime for all child hosts */
+	BOOST_FOREACH(const Checkable::Ptr& child, host->GetChildren()) {
+		Host::Ptr host;
+		Service::Ptr service;
+		tie(host, service) = GetHostService(child);
+
+		/* ignore all service children */
+		if (service)
+			continue;
+
+		(void) Downtime::AddDowntime(child, arguments[6], arguments[7],
+		    Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+		    Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
+	}
+}
+
+void ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime(double, const std::vector<String>& arguments)
+{
+	Host::Ptr host = Host::GetByName(arguments[0]);
+
+	if (!host)
+		BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule and propagate triggered host downtime for non-existent host '" + arguments[0] + "'"));
+
+	String triggeredBy;
+	int triggeredByLegacy = Convert::ToLong(arguments[4]);
+	int is_fixed = Convert::ToLong(arguments[3]);
+	if (triggeredByLegacy != 0)
+		triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
+
+	Log(LogNotice, "ExternalCommandProcessor")
+	    << "Creating downtime for host " << host->GetName();
+
+	String parentDowntime = Downtime::AddDowntime(host, arguments[6], arguments[7],
+	    Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+	    Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
+
+	/* Schedule downtime for all child hosts and explicitely trigger them through the parent host's downtime */
+	BOOST_FOREACH(const Checkable::Ptr& child, host->GetChildren()) {
+		Host::Ptr host;
+		Service::Ptr service;
+		tie(host, service) = GetHostService(child);
+
+		/* ignore all service children */
+		if (service)
+			continue;
+
+		(void) Downtime::AddDowntime(child, arguments[6], arguments[7],
+		    Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+		    Convert::ToBool(is_fixed), parentDowntime, Convert::ToDouble(arguments[5]));
+	}
+}
+
 void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>& arguments)
 {
 	int id = Convert::ToLong(arguments[0]);
diff --git a/lib/icinga/externalcommandprocessor.hpp b/lib/icinga/externalcommandprocessor.hpp
index 0596532..8dcdbfb 100644
--- a/lib/icinga/externalcommandprocessor.hpp
+++ b/lib/icinga/externalcommandprocessor.hpp
@@ -82,6 +82,8 @@ private:
 	static void ScheduleSvcDowntime(double time, const std::vector<String>& arguments);
 	static void DelSvcDowntime(double time, const std::vector<String>& arguments);
 	static void ScheduleHostDowntime(double time, const std::vector<String>& arguments);
+	static void ScheduleAndPropagateHostDowntime(double, const std::vector<String>& arguments);
+	static void ScheduleAndPropagateTriggeredHostDowntime(double, const std::vector<String>& arguments);
 	static void DelHostDowntime(double time, const std::vector<String>& arguments);
 	static void DelDowntimeByHostName(double, const std::vector<String>& arguments);
 	static void ScheduleHostSvcDowntime(double time, const std::vector<String>& arguments);



More information about the icinga-checkins mailing list