From bb0dcdf0b4017106c2f16572d5652b101d68ad5e Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Fri, 3 Sep 2021 12:05:34 +0200 Subject: [PATCH] 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 2980bae65..89ca3b9f3 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -434,7 +434,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(); @@ -451,10 +465,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;