{ "legacy_id", downtime->GetLegacyId() }
});
+ /* Schedule downtime for all services for the host type. */
+ bool allServices = false;
+
+ if (params->Contains("all_services"))
+ allServices = HttpUtility::GetLastParameter(params, "all_services");
+
+ if (allServices && !service) {
+ ArrayData serviceDowntimes;
+
+ for (const Service::Ptr& hostService : host->GetServices()) {
+ Log(LogNotice, "ApiActions")
+ << "Creating downtime for service " << hostService->GetName() << " on host " << host->GetName();
+
+ String serviceDowntimeName = Downtime::AddDowntime(hostService, author, comment, startTime, endTime,
+ fixed, triggerName, duration);
+
+ Downtime::Ptr serviceDowntime = Downtime::GetByName(serviceDowntimeName);
+
+ serviceDowntimes.push_back(new Dictionary({
+ { "name", serviceDowntimeName },
+ { "legacy_id", serviceDowntime->GetLegacyId() }
+ }));
+ }
+
+ additional->Set("service_downtimes", new Array(std::move(serviceDowntimes)));
+ }
+
/* Schedule downtime for all child objects. */
if (childOptions != DowntimeNoChildren) {
/* 'DowntimeTriggeredChildren' schedules child downtimes triggered by the parent downtime.
Downtime::Ptr childDowntime = Downtime::GetByName(childDowntimeName);
- childDowntimes.push_back(new Dictionary({
+ Dictionary::Ptr childAdditional = new Dictionary({
{ "name", childDowntimeName },
{ "legacy_id", childDowntime->GetLegacyId() }
- }));
- }
+ });
- additional->Set("child_downtimes", new Array(std::move(childDowntimes)));
- }
+ /* For a host, also schedule all service downtimes if requested. */
+ Host::Ptr childHost;
+ Service::Ptr childService;
+ tie(childHost, childService) = GetHostService(child);
- /* Schedule downtime for all services for the host type. */
- bool allServices = false;
+ if (allServices && !childService) {
+ ArrayData childServiceDowntimes;
- if (params->Contains("all_services"))
- allServices = HttpUtility::GetLastParameter(params, "all_services");
+ for (const Service::Ptr& hostService : host->GetServices()) {
+ Log(LogNotice, "ApiActions")
+ << "Creating downtime for service " << hostService->GetName() << " on child host " << host->GetName();
- if (allServices && !service) {
- ArrayData serviceDowntimes;
+ String serviceDowntimeName = Downtime::AddDowntime(hostService, author, comment, startTime, endTime,
+ fixed, triggerName, duration);
- for (const Service::Ptr& hostService : host->GetServices()) {
- Log(LogNotice, "ApiActions")
- << "Creating downtime for service " << hostService->GetName() << " on host " << host->GetName();
+ Downtime::Ptr serviceDowntime = Downtime::GetByName(serviceDowntimeName);
- String serviceDowntimeName = Downtime::AddDowntime(hostService, author, comment, startTime, endTime,
- fixed, triggerName, duration);
+ childServiceDowntimes.push_back(new Dictionary({
+ { "name", serviceDowntimeName },
+ { "legacy_id", serviceDowntime->GetLegacyId() }
+ }));
+ }
- Downtime::Ptr serviceDowntime = Downtime::GetByName(serviceDowntimeName);
+ childAdditional->Set("service_downtimes", new Array(std::move(childServiceDowntimes)));
+ }
- serviceDowntimes.push_back(new Dictionary({
- { "name", serviceDowntimeName },
- { "legacy_id", serviceDowntime->GetLegacyId() }
- }));
+ childDowntimes.push_back(childAdditional);
}
- additional->Set("service_downtimes", new Array(std::move(serviceDowntimes)));
+ additional->Set("child_downtimes", new Array(std::move(childDowntimes)));
}
return ApiActions::CreateResult(200, "Successfully scheduled downtime '" +