mirror of https://github.com/Icinga/icinga2.git
Add child_options for API action 'schedule-downtime'
fixes #10896 fixes #10897
This commit is contained in:
parent
ea1f8727da
commit
09658f6d0e
|
@ -986,6 +986,7 @@ Send a `POST` request to the URL endpoint `/v1/actions/schedule-downtime`.
|
||||||
duration | integer | **Required.** Duration of the downtime in seconds if `fixed` is set to false.
|
duration | integer | **Required.** Duration of the downtime in seconds if `fixed` is set to false.
|
||||||
fixed | boolean | **Optional.** Defaults to `true`. If true, the downtime is `fixed` otherwise `flexible`. See [downtimes](8-advanced-topics.md#downtimes) for more information.
|
fixed | boolean | **Optional.** Defaults to `true`. If true, the downtime is `fixed` otherwise `flexible`. See [downtimes](8-advanced-topics.md#downtimes) for more information.
|
||||||
trigger\_name | string | **Optional.** Sets the trigger for a triggered downtime. See [downtimes](8-advanced-topics.md#downtimes) for more information on triggered downtimes.
|
trigger\_name | string | **Optional.** Sets the trigger for a triggered downtime. See [downtimes](8-advanced-topics.md#downtimes) for more information on triggered downtimes.
|
||||||
|
child\_options | integer | **Optional.** Schedule child downtimes. `0` does not do anything, `1` schedules child downtimes triggered by this downtime, `2` schedules non-triggered downtimes. Defaults to `0`.
|
||||||
|
|
||||||
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` and `Service`.
|
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` and `Service`.
|
||||||
|
|
||||||
|
|
|
@ -315,13 +315,21 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
|
||||||
if (!fixed && !params->Contains("duration"))
|
if (!fixed && !params->Contains("duration"))
|
||||||
return ApiActions::CreateResult(404, "Option 'duration' is required for flexible downtime");
|
return ApiActions::CreateResult(404, "Option 'duration' is required for flexible downtime");
|
||||||
|
|
||||||
String downtimeName = Downtime::AddDowntime(checkable,
|
double duration = 0.0;
|
||||||
HttpUtility::GetLastParameter(params, "author"),
|
if (params->Contains("duration"))
|
||||||
HttpUtility::GetLastParameter(params, "comment"),
|
duration = HttpUtility::GetLastParameter(params, "duration");
|
||||||
HttpUtility::GetLastParameter(params, "start_time"),
|
|
||||||
HttpUtility::GetLastParameter(params, "end_time"), fixed,
|
String triggerName;
|
||||||
HttpUtility::GetLastParameter(params, "trigger_name"),
|
if (params->Contains("trigger_name"))
|
||||||
HttpUtility::GetLastParameter(params, "duration"));
|
triggerName = HttpUtility::GetLastParameter(params, "trigger_name");
|
||||||
|
|
||||||
|
String author = HttpUtility::GetLastParameter(params, "author");
|
||||||
|
String comment = HttpUtility::GetLastParameter(params, "comment");
|
||||||
|
double startTime = HttpUtility::GetLastParameter(params, "start_time");
|
||||||
|
double endTime = HttpUtility::GetLastParameter(params, "end_time");
|
||||||
|
|
||||||
|
String downtimeName = Downtime::AddDowntime(checkable, author, comment, startTime, endTime,
|
||||||
|
fixed, triggerName, duration);
|
||||||
|
|
||||||
Downtime::Ptr downtime = Downtime::GetByName(downtimeName);
|
Downtime::Ptr downtime = Downtime::GetByName(downtimeName);
|
||||||
|
|
||||||
|
@ -329,6 +337,44 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
|
||||||
additional->Set("name", downtimeName);
|
additional->Set("name", downtimeName);
|
||||||
additional->Set("legacy_id", downtime->GetLegacyId());
|
additional->Set("legacy_id", downtime->GetLegacyId());
|
||||||
|
|
||||||
|
/* Schedule downtime for all child objects. */
|
||||||
|
int childOptions = 0;
|
||||||
|
if (params->Contains("child_options"))
|
||||||
|
childOptions = HttpUtility::GetLastParameter(params, "child_options");
|
||||||
|
|
||||||
|
if (childOptions > 0) {
|
||||||
|
/* '1' schedules child downtimes triggered by the parent downtime.
|
||||||
|
* '2' schedules non-triggered downtimes for all children.
|
||||||
|
*/
|
||||||
|
if (childOptions == 1)
|
||||||
|
triggerName = downtimeName;
|
||||||
|
|
||||||
|
Array::Ptr childDowntimes = new Array();
|
||||||
|
|
||||||
|
Log(LogCritical, "ApiActions")
|
||||||
|
<< "Processing child options " << childOptions << " for downtime " << downtimeName;
|
||||||
|
|
||||||
|
for (const Checkable::Ptr& child : checkable->GetAllChildren()) {
|
||||||
|
Log(LogCritical, "ApiActions")
|
||||||
|
<< "Scheduling downtime for child object " << child->GetName();
|
||||||
|
|
||||||
|
String childDowntimeName = Downtime::AddDowntime(child, author, comment, startTime, endTime,
|
||||||
|
fixed, triggerName, duration);
|
||||||
|
|
||||||
|
Log(LogCritical, "ApiActions")
|
||||||
|
<< "Add child downtime '" << childDowntimeName << "'.";
|
||||||
|
|
||||||
|
Downtime::Ptr childDowntime = Downtime::GetByName(childDowntimeName);
|
||||||
|
|
||||||
|
Dictionary::Ptr additionalChild = new Dictionary();
|
||||||
|
additionalChild->Set("name", childDowntimeName);
|
||||||
|
additionalChild->Set("legacy_id", childDowntime->GetLegacyId());
|
||||||
|
childDowntimes->Add(additionalChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
additional->Set("child_downtimes", 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,17 +262,18 @@ String Downtime::AddDowntime(const Checkable::Ptr& checkable, const String& auth
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!triggeredBy.IsEmpty()) {
|
if (!triggeredBy.IsEmpty()) {
|
||||||
Downtime::Ptr triggerDowntime = Downtime::GetByName(triggeredBy);
|
Downtime::Ptr parentDowntime = Downtime::GetByName(triggeredBy);
|
||||||
Array::Ptr triggers = triggerDowntime->GetTriggers();
|
Array::Ptr triggers = parentDowntime->GetTriggers();
|
||||||
|
|
||||||
if (!triggers->Contains(triggeredBy))
|
ObjectLock olock(triggers);
|
||||||
triggers->Add(triggeredBy);
|
if (!triggers->Contains(fullName))
|
||||||
|
triggers->Add(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Downtime::Ptr downtime = Downtime::GetByName(fullName);
|
Downtime::Ptr downtime = Downtime::GetByName(fullName);
|
||||||
|
|
||||||
if (!downtime)
|
if (!downtime)
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create downtime."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create downtime object."));
|
||||||
|
|
||||||
Log(LogNotice, "Downtime")
|
Log(LogNotice, "Downtime")
|
||||||
<< "Added downtime '" << downtime->GetName()
|
<< "Added downtime '" << downtime->GetName()
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Downtime : ConfigObject < DowntimeNameComposer
|
||||||
[state] Timestamp trigger_time;
|
[state] Timestamp trigger_time;
|
||||||
[config] bool fixed;
|
[config] bool fixed;
|
||||||
[config] Timestamp duration;
|
[config] Timestamp duration;
|
||||||
[config] name(Downtime) triggered_by;
|
[config] String triggered_by;
|
||||||
[config] String scheduled_by;
|
[config] String scheduled_by;
|
||||||
[state] Array::Ptr triggers {
|
[state] Array::Ptr triggers {
|
||||||
default {{{ return new Array(); }}}
|
default {{{ return new Array(); }}}
|
||||||
|
|
Loading…
Reference in New Issue