mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
Combine all_services with child_options for schedule-downtime API action
This commit is contained in:
parent
e7c4253fa3
commit
f6fc81c6c3
@ -1381,7 +1381,7 @@ Send a `POST` request to the URL endpoint `/v1/actions/schedule-downtime`.
|
|||||||
end\_time | Timestamp | **Required.** Timestamp marking the end of the downtime.
|
end\_time | Timestamp | **Required.** Timestamp marking the end of the downtime.
|
||||||
fixed | Boolean | **Optional.** Defaults to `true`. If true, the downtime is `fixed` otherwise `flexible`. See [downtimes](08-advanced-topics.md#downtimes) for more information.
|
fixed | Boolean | **Optional.** Defaults to `true`. If true, the downtime is `fixed` otherwise `flexible`. See [downtimes](08-advanced-topics.md#downtimes) for more information.
|
||||||
duration | Number | **Required for flexible downtimes.** Duration of the downtime in seconds if `fixed` is set to false.
|
duration | Number | **Required for flexible downtimes.** Duration of the downtime in seconds if `fixed` is set to false.
|
||||||
all\_services | Boolean | **Optional for host downtimes.** Sets downtime for [all services](12-icinga2-api.md#icinga2-api-actions-schedule-downtime-host-all-services) for the matched host objects. Defaults to `false`.
|
all\_services | Boolean | **Optional for host downtimes.** Sets downtime for [all services](12-icinga2-api.md#icinga2-api-actions-schedule-downtime-host-all-services) for the matched host objects. If `child_options` are set, all child hosts and their services will schedule a downtime too. Defaults to `false`.
|
||||||
trigger\_name | String | **Optional.** Sets the trigger for a triggered downtime. See [downtimes](08-advanced-topics.md#downtimes) for more information on triggered downtimes.
|
trigger\_name | String | **Optional.** Sets the trigger for a triggered downtime. See [downtimes](08-advanced-topics.md#downtimes) for more information on triggered downtimes.
|
||||||
child\_options| String | **Optional.** Schedule child downtimes. `DowntimeNoChildren` does not do anything, `DowntimeTriggeredChildren` schedules child downtimes triggered by this downtime, `DowntimeNonTriggeredChildren` schedules non-triggered downtimes. Defaults to `DowntimeNoChildren`.
|
child\_options| String | **Optional.** Schedule child downtimes. `DowntimeNoChildren` does not do anything, `DowntimeTriggeredChildren` schedules child downtimes triggered by this downtime, `DowntimeNonTriggeredChildren` schedules non-triggered downtimes. Defaults to `DowntimeNoChildren`.
|
||||||
|
|
||||||
|
@ -361,40 +361,6 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
|
|||||||
{ "legacy_id", downtime->GetLegacyId() }
|
{ "legacy_id", downtime->GetLegacyId() }
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Schedule downtime for all child objects. */
|
|
||||||
if (childOptions != DowntimeNoChildren) {
|
|
||||||
/* 'DowntimeTriggeredChildren' schedules child downtimes triggered by the parent downtime.
|
|
||||||
* 'DowntimeNonTriggeredChildren' schedules non-triggered downtimes for all children.
|
|
||||||
*/
|
|
||||||
if (childOptions == DowntimeTriggeredChildren)
|
|
||||||
triggerName = downtimeName;
|
|
||||||
|
|
||||||
Log(LogNotice, "ApiActions")
|
|
||||||
<< "Processing child options " << childOptions << " for downtime " << downtimeName;
|
|
||||||
|
|
||||||
ArrayData childDowntimes;
|
|
||||||
|
|
||||||
for (const Checkable::Ptr& child : checkable->GetAllChildren()) {
|
|
||||||
Log(LogNotice, "ApiActions")
|
|
||||||
<< "Scheduling downtime for child object " << child->GetName();
|
|
||||||
|
|
||||||
String childDowntimeName = Downtime::AddDowntime(child, author, comment, startTime, endTime,
|
|
||||||
fixed, triggerName, duration);
|
|
||||||
|
|
||||||
Log(LogNotice, "ApiActions")
|
|
||||||
<< "Add child downtime '" << childDowntimeName << "'.";
|
|
||||||
|
|
||||||
Downtime::Ptr childDowntime = Downtime::GetByName(childDowntimeName);
|
|
||||||
|
|
||||||
childDowntimes.push_back(new Dictionary({
|
|
||||||
{ "name", childDowntimeName },
|
|
||||||
{ "legacy_id", childDowntime->GetLegacyId() }
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
additional->Set("child_downtimes", new Array(std::move(childDowntimes)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Schedule downtime for all services for the host type. */
|
/* Schedule downtime for all services for the host type. */
|
||||||
bool allServices = false;
|
bool allServices = false;
|
||||||
|
|
||||||
@ -422,6 +388,68 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
|
|||||||
additional->Set("service_downtimes", new Array(std::move(serviceDowntimes)));
|
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.
|
||||||
|
* 'DowntimeNonTriggeredChildren' schedules non-triggered downtimes for all children.
|
||||||
|
*/
|
||||||
|
if (childOptions == DowntimeTriggeredChildren)
|
||||||
|
triggerName = downtimeName;
|
||||||
|
|
||||||
|
Log(LogNotice, "ApiActions")
|
||||||
|
<< "Processing child options " << childOptions << " for downtime " << downtimeName;
|
||||||
|
|
||||||
|
ArrayData childDowntimes;
|
||||||
|
|
||||||
|
for (const Checkable::Ptr& child : checkable->GetAllChildren()) {
|
||||||
|
Log(LogNotice, "ApiActions")
|
||||||
|
<< "Scheduling downtime for child object " << child->GetName();
|
||||||
|
|
||||||
|
String childDowntimeName = Downtime::AddDowntime(child, author, comment, startTime, endTime,
|
||||||
|
fixed, triggerName, duration);
|
||||||
|
|
||||||
|
Log(LogNotice, "ApiActions")
|
||||||
|
<< "Add child downtime '" << childDowntimeName << "'.";
|
||||||
|
|
||||||
|
Downtime::Ptr childDowntime = Downtime::GetByName(childDowntimeName);
|
||||||
|
|
||||||
|
Dictionary::Ptr childAdditional = new Dictionary({
|
||||||
|
{ "name", childDowntimeName },
|
||||||
|
{ "legacy_id", childDowntime->GetLegacyId() }
|
||||||
|
});
|
||||||
|
|
||||||
|
/* 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()) {
|
||||||
|
Log(LogNotice, "ApiActions")
|
||||||
|
<< "Creating downtime for service " << hostService->GetName() << " on child host " << host->GetName();
|
||||||
|
|
||||||
|
String serviceDowntimeName = Downtime::AddDowntime(hostService, author, comment, startTime, endTime,
|
||||||
|
fixed, triggerName, duration);
|
||||||
|
|
||||||
|
Downtime::Ptr serviceDowntime = Downtime::GetByName(serviceDowntimeName);
|
||||||
|
|
||||||
|
childServiceDowntimes.push_back(new Dictionary({
|
||||||
|
{ "name", serviceDowntimeName },
|
||||||
|
{ "legacy_id", serviceDowntime->GetLegacyId() }
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
childAdditional->Set("service_downtimes", new Array(std::move(childServiceDowntimes)));
|
||||||
|
}
|
||||||
|
|
||||||
|
childDowntimes.push_back(childAdditional);
|
||||||
|
}
|
||||||
|
|
||||||
|
additional->Set("child_downtimes", new Array(std::move(childDowntimes)));
|
||||||
|
}
|
||||||
|
|
||||||
return ApiActions::CreateResult(200, "Successfully scheduled downtime '" +
|
return ApiActions::CreateResult(200, "Successfully scheduled downtime '" +
|
||||||
downtimeName + "' for object '" + checkable->GetName() + "'.", additional);
|
downtimeName + "' for object '" + checkable->GetName() + "'.", additional);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user