From f298314216d4a03cecc824fa6771138f95c7f115 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Thu, 2 Sep 2021 16:18:55 +0200 Subject: [PATCH 1/3] Fix scheduling of downtimes for all services on child hosts The loop iterated over the services of the wrong host resulting in duplicate downtimes scheduled for services of the parent host instead of downtimes for services of the child host. --- lib/icinga/apiactions.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 4ecbf39e1..0095add82 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -442,12 +442,12 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object, if (allServices && !childService) { ArrayData childServiceDowntimes; - for (const Service::Ptr& hostService : host->GetServices()) { + for (const Service::Ptr& childService : childHost->GetServices()) { Log(LogNotice, "ApiActions") - << "Creating downtime for service " << hostService->GetName() << " on child host " << host->GetName(); + << "Creating downtime for service " << childService->GetName() << " on child host " << childHost->GetName(); - Downtime::Ptr serviceDowntime = Downtime::AddDowntime(hostService, author, comment, startTime, endTime, - fixed, triggerName, duration); + Downtime::Ptr serviceDowntime = Downtime::AddDowntime(childService, author, comment, startTime, endTime, + fixed, triggerName, duration, String(), String(), childDowntimeName); String serviceDowntimeName = serviceDowntime->GetName(); childServiceDowntimes.push_back(new Dictionary({ From b9e24991483de73df6b8aed19573826e597bbc02 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Fri, 3 Sep 2021 12:05:34 +0200 Subject: [PATCH 2/3] Prevent duplicate donwtimes when combining child_options and all_services --- lib/icinga/apiactions.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 0095add82..37f9d8b41 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -418,7 +418,21 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object, ArrayData childDowntimes; - for (const Checkable::Ptr& child : checkable->GetAllChildren()) { + std::set allChildren = checkable->GetAllChildren(); + for (const Checkable::Ptr& child : allChildren) { + Host::Ptr childHost; + Service::Ptr childService; + tie(childHost, childService) = GetHostService(child); + + if (allServices && childService && + allChildren.find(static_pointer_cast(childHost)) != allChildren.end()) { + /* When scheduling downtimes for all service and all children, the current child is a service, and its + * host is also a child, skip it here. The downtime for this service will be scheduled below together + * with the downtimes of all services for that host. Scheduling it below ensures that the relation + * from the child service downtime to the child host downtime is set properly. */ + continue; + } + Log(LogNotice, "ApiActions") << "Scheduling downtime for child object " << child->GetName(); @@ -435,10 +449,6 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object, }); /* For a host, also schedule all service downtimes if requested. */ - Host::Ptr childHost; - Service::Ptr childService; - tie(childHost, childService) = GetHostService(child); - if (allServices && !childService) { ArrayData childServiceDowntimes; From 8b3bd062acd082b3648fdec22da3f95241f0a11c Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Fri, 19 Nov 2021 14:47:07 +0100 Subject: [PATCH 3/3] Document which other downtimes are deleted by /v1/actions/remove-downtime --- doc/12-icinga2-api.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/12-icinga2-api.md b/doc/12-icinga2-api.md index 6f8f296c6..805cf35dc 100644 --- a/doc/12-icinga2-api.md +++ b/doc/12-icinga2-api.md @@ -1395,6 +1395,9 @@ Send a `POST` request to the URL endpoint `/v1/actions/remove-downtime`. In addition to these parameters a [filter](12-icinga2-api.md#icinga2-api-filters) must be provided. The valid types for this action are `Host`, `Service` and `Downtime`. +When removing a host downtime, service downtimes on this host are automatically deleted if they were created using +the `all_services` option. Other downtimes created using the `child_options` option are not affected. + Example for a simple filter using the `downtime` URL parameter: ```