]> granicus.if.org Git - icinga2/commitdiff
Implement external command DEL_DOWNTIME_BY_HOST_NAME
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 31 Jul 2015 12:46:38 +0000 (14:46 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 31 Jul 2015 12:50:17 +0000 (14:50 +0200)
Required by Classic UI 1.x, this will hopefully reduce
the noise on non-working commands with the old legacy stuff.

fixes #8979

doc/22-appendix.md
lib/icinga/externalcommandprocessor.cpp
lib/icinga/externalcommandprocessor.hpp

index 49c66da37feca9536705340d05528016a9aa0ac9..44f7bfc117277ca826599b0b3d5df6de020ad789 100644 (file)
@@ -49,6 +49,7 @@ Additional details can be found in the [Icinga 1.x Documentation](http://docs.ic
   DEL_SVC_DOWNTIME                          | ;&lt;downtime_id&gt; (1)   | -
   SCHEDULE_HOST_DOWNTIME                    | ;&lt;host_name&gt;;&lt;start_time&gt;;&lt;end_time&gt;;&lt;fixed&gt;;&lt;trigger_id&gt;;&lt;duration&gt;;&lt;author&gt;;&lt;comment&gt; (8)  | -
   DEL_HOST_DOWNTIME                         | ;&lt;downtime_id&gt; (1)  | -
+  DEL_DOWNTIME_BY_HOST_NAME                 | ;&lt;host_name&gt;[;&lt;service_name;&gt;[;&lt;start_time;&gt;[;&lt;comment_text;&gt;]]] (1)  | -
   SCHEDULE_HOST_SVC_DOWNTIME                | ;&lt;host_name&gt;;&lt;start_time&gt;;&lt;end_time&gt;;&lt;fixed&gt;;&lt;trigger_id&gt;;&lt;duration&gt;;&lt;author&gt;;&lt;comment&gt; (8)  | -
   SCHEDULE_HOSTGROUP_HOST_DOWNTIME          | ;&lt;hostgroup_name&gt;;&lt;start_time&gt;;&lt;end_time&gt;;&lt;fixed&gt;;&lt;trigger_id&gt;;&lt;duration&gt;;&lt;author&gt;;&lt;comment&gt; (8)  | -
   SCHEDULE_HOSTGROUP_SVC_DOWNTIME           | ;&lt;hostgroup_name&gt;;&lt;start_time&gt;;&lt;end_time&gt;;&lt;fixed&gt;;&lt;trigger_id&gt;;&lt;duration&gt;;&lt;author&gt;;&lt;comment&gt; (8)  | -
index 6eb7af0d25eea9e1d3ed5fa8673ee03c363f7887..06ee7361c14feaa241c0df08d612654865510df9 100644 (file)
@@ -215,6 +215,7 @@ void ExternalCommandProcessor::StaticInitialize(void)
        RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime, 1);
        RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime, 8);
        RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime, 1);
+       RegisterCommand("DEL_DOWNTIME_BY_HOST_NAME", &ExternalCommandProcessor::DelDowntimeByHostName, 1);
        RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime, 8);
        RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime, 8);
        RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime, 8);
@@ -1077,6 +1078,67 @@ void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>
        Service::RemoveDowntime(rid, true);
 }
 
+void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector<String>& arguments)
+{
+       Host::Ptr host = Host::GetByName(arguments[0]);
+
+       if (!host)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host services downtime for non-existent host '" + arguments[0] + "'"));
+
+       String serviceName;
+       if (arguments.size() >= 2)
+               serviceName = arguments[1];
+
+       String startTime;
+       if (arguments.size() >= 3)
+               startTime = arguments[2];
+
+       String commentString;
+       if (arguments.size() >= 4)
+               commentString = arguments[3];
+
+       if (arguments.size() > 5)
+               Log(LogWarning, "ExternalCommandProcessor")
+                   << ("Ignoring additional parameters for host '" + arguments[0] + "' downtime deletion.");
+
+       std::vector<String> ids;
+
+       Dictionary::Ptr hostDowntimes = host->GetDowntimes();
+       {
+               ObjectLock dhlock(hostDowntimes);
+               BOOST_FOREACH(const Dictionary::Pair& kv, hostDowntimes) {
+                       ids.push_back(kv.first);
+               }
+       }
+
+       BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
+               if (!serviceName.IsEmpty() && serviceName != service->GetName())
+                       continue;
+
+               Dictionary::Ptr serviceDowntimes = service->GetDowntimes();
+               {
+                       ObjectLock dslock(serviceDowntimes);
+                       BOOST_FOREACH(const Dictionary::Pair& kv, serviceDowntimes) {
+                               ids.push_back(kv.first);
+                       }
+               }
+       }
+
+       BOOST_FOREACH(const String& id, ids) {
+               Downtime::Ptr downtime = Service::GetDowntimeByID(id);
+
+               if (!startTime.IsEmpty() && downtime->GetStartTime() != Convert::ToDouble(startTime))
+                       continue;
+
+               if (!commentString.IsEmpty() && downtime->GetComment() != commentString)
+                       continue;
+
+               Log(LogNotice, "ExternalCommandProcessor")
+                   << "Removing downtime ID " << id;
+               Service::RemoveDowntime(id, true);
+       }
+}
+
 void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector<String>& arguments)
 {
        Host::Ptr host = Host::GetByName(arguments[0]);
index cebb90f4e6b517dc40707e2d328ef5c2de1b3979..72072bf871f13925047a4dc841b868b88ac9c605 100644 (file)
@@ -81,6 +81,7 @@ private:
        static void DelSvcDowntime(double time, const std::vector<String>& arguments);
        static void ScheduleHostDowntime(double time, 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);
        static void ScheduleHostgroupHostDowntime(double time, const std::vector<String>& arguments);
        static void ScheduleHostgroupSvcDowntime(double time, const std::vector<String>& arguments);