fixed | Boolean | **Optional.** Whether this is a fixed downtime. Defaults to `true`.
duration | Duration | **Optional.** How long the downtime lasts. Only has an effect for flexible (non-fixed) downtimes.
ranges | Dictionary | **Required.** A dictionary containing information which days and durations apply to this timeperiod.
+ child\_options | String | **Optional.** Schedule child downtimes. `DowntimeNoChildren` does not do anything, `DowntimeTriggeredChildren` schedules child downtimes triggered by this downtime, `DowntimeTriggeredChildren` schedules non-triggered downtimes. Defaults to `DowntimeNoChildren`.
ScheduledDowntime objects have composite names, i.e. their names are based
on the `host_name` and `service_name` attributes and the
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.
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 | Number | **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`.
+ child\_options| String | **Optional.** Schedule child downtimes. `DowntimeNoChildren` does not do anything, `DowntimeTriggeredChildren` schedules child downtimes triggered by this downtime, `DowntimeTriggeredChildren` schedules non-triggered downtimes. Defaults to `DowntimeNoChildren`.
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`.
});
/* Schedule downtime for all child objects. */
- int childOptions = 0;
+ DowntimeChildOptions childOptions = DowntimeNoChildren;
if (params->Contains("child_options"))
- childOptions = HttpUtility::GetLastParameter(params, "child_options");
+ childOptions = Downtime::ChildOptionsFromValue(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 != DowntimeNoChildren) {
+ /* 'DowntimeTriggeredChildren' schedules child downtimes triggered by the parent downtime.
+ * 'DowntimeNonTriggeredChildren' schedules non-triggered downtimes for all children.
*/
- if (childOptions == 1)
+ if (childOptions == DowntimeTriggeredChildren)
triggerName = downtimeName;
- Log(LogCritical, "ApiActions")
+ Log(LogNotice, "ApiActions")
<< "Processing child options " << childOptions << " for downtime " << downtimeName;
ArrayData childDowntimes;
for (const Checkable::Ptr& child : checkable->GetAllChildren()) {
- Log(LogCritical, "ApiActions")
+ Log(LogNotice, "ApiActions")
<< "Scheduling downtime for child object " << child->GetName();
String childDowntimeName = Downtime::AddDowntime(child, author, comment, startTime, endTime,
fixed, triggerName, duration);
- Log(LogCritical, "ApiActions")
+ Log(LogNotice, "ApiActions")
<< "Add child downtime '" << childDowntimeName << "'.";
Downtime::Ptr childDowntime = Downtime::GetByName(childDowntimeName);
REGISTER_TYPE(Downtime);
+INITIALIZE_ONCE(&Downtime::StaticInitialize);
+
+void Downtime::StaticInitialize()
+{
+ ScriptGlobal::Set("DowntimeNoChildren", "DowntimeNoChildren");
+ ScriptGlobal::Set("DowntimeTriggeredChildren", "DowntimeTriggeredChildren");
+ ScriptGlobal::Set("DowntimeNonTriggeredChildren", "DowntimeNonTriggeredChildren");
+}
+
String DowntimeNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const
{
Downtime::Ptr downtime = dynamic_pointer_cast<Downtime>(context);
if (lvalue() <= 0)
BOOST_THROW_EXCEPTION(ValidationError(this, { "end_time" }, "End time must be greater than 0."));
}
+
+DowntimeChildOptions Downtime::ChildOptionsFromValue(const Value& options)
+{
+ if (options == "DowntimeNoChildren")
+ return DowntimeNoChildren;
+ else if (options == "DowntimeTriggeredChildren")
+ return DowntimeTriggeredChildren;
+ else if (options == "DowntimeNonTriggeredChildren")
+ return DowntimeNonTriggeredChildren;
+ else if (options.IsNumber()) {
+ int number = options;
+ if (number >= 0 && number <= 2)
+ return static_cast<DowntimeChildOptions>(number);
+ }
+
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid child option specified"));
+}
namespace icinga
{
+enum DowntimeChildOptions
+{
+ DowntimeNoChildren,
+ DowntimeTriggeredChildren,
+ DowntimeNonTriggeredChildren
+};
+
/**
* A downtime.
*
bool IsExpired() const;
bool HasValidConfigOwner() const;
+ static void StaticInitialize();
+
static int GetNextDowntimeID();
static String AddDowntime(const intrusive_ptr<Checkable>& checkable, const String& author,
static String GetDowntimeIDFromLegacyID(int id);
+ static DowntimeChildOptions ChildOptionsFromValue(const Value& options);
+
protected:
void OnAllConfigLoaded() override;
void Start(bool runtimeCreated) override;
return;
}
- Downtime::AddDowntime(GetCheckable(), GetAuthor(), GetComment(),
+ String downtimeName = Downtime::AddDowntime(GetCheckable(), GetAuthor(), GetComment(),
segment.first, segment.second,
GetFixed(), String(), GetDuration(), GetName(), GetName());
+
+ Downtime::Ptr downtime = Downtime::GetByName(downtimeName);
+
+ int childOptions = Downtime::ChildOptionsFromValue(GetChildOptions());
+ if (childOptions > 0) {
+ /* 'DowntimeTriggeredChildren' schedules child downtimes triggered by the parent downtime.
+ * 'DowntimeNonTriggeredChildren' schedules non-triggered downtimes for all children.
+ */
+ String triggerName;
+ if (childOptions == 1)
+ triggerName = downtimeName;
+
+ Log(LogNotice, "ScheduledDowntime")
+ << "Processing child options " << childOptions << " for downtime " << downtimeName;
+
+ for (const Checkable::Ptr& child : GetCheckable()->GetAllChildren()) {
+ Log(LogNotice, "ScheduledDowntime")
+ << "Scheduling downtime for child object " << child->GetName();
+
+ String childDowntimeName = Downtime::AddDowntime(child, GetAuthor(), GetComment(),
+ segment.first, segment.second, GetFixed(), triggerName, GetDuration(), GetName(), GetName());
+
+ Log(LogNotice, "ScheduledDowntime")
+ << "Add child downtime '" << childDowntimeName << "'.";
+ }
+ }
}
void ScheduledDowntime::ValidateRanges(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils)
}
}
+void ScheduledDowntime::ValidateChildOptions(const Lazy<Value>& lvalue, const ValidationUtils& utils)
+{
+ ObjectImpl<ScheduledDowntime>::ValidateChildOptions(lvalue, utils);
+
+ try {
+ Downtime::ChildOptionsFromValue(lvalue());
+ } catch (const std::exception&) {
+ BOOST_THROW_EXCEPTION(ValidationError(this, { "child_options" }, "Invalid child_options specified"));
+ }
+}
\ No newline at end of file
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
void ValidateRanges(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
+ void ValidateChildOptions(const Lazy<Value>& lvalue, const ValidationUtils& utils) override;
protected:
void OnAllConfigLoaded() override;
default {{{ return true; }}}
};
+ [config] Value child_options {
+ default {{{ return "DowntimeNoChildren"; }}}
+ };
+
[config, required] Dictionary::Ptr ranges;
};