Skip to content

Fix scheduling of downtimes for all services on child hosts #9184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/12-icinga2-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down
28 changes: 19 additions & 9 deletions lib/icinga/apiactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,21 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,

ArrayData childDowntimes;

for (const Checkable::Ptr& child : checkable->GetAllChildren()) {
std::set<Checkable::Ptr> 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<Checkable>(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();

Expand All @@ -435,19 +449,15 @@ 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;

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({
Expand Down