]> granicus.if.org Git - icinga2/commitdiff
Improve error handling for invalid child_options for API downtime actions
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 24 Oct 2018 09:00:24 +0000 (11:00 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 29 Oct 2018 12:52:43 +0000 (13:52 +0100)
fixes #6712

lib/icinga/apiactions.cpp

index 22684c9a20bae29043356bcff4dfbb44de99d0a4..127f28aa4ad549e625c6b9f45fe6045937c677b5 100644 (file)
@@ -355,6 +355,15 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
        double startTime = HttpUtility::GetLastParameter(params, "start_time");
        double endTime = HttpUtility::GetLastParameter(params, "end_time");
 
+       DowntimeChildOptions childOptions = DowntimeNoChildren;
+       if (params->Contains("child_options")) {
+               try {
+                       childOptions = Downtime::ChildOptionsFromValue(HttpUtility::GetLastParameter(params, "child_options"));
+               } catch (const std::exception&) {
+                       return ApiActions::CreateResult(400, "Option 'child_options' provided an invalid value.");
+               }
+       }
+
        String downtimeName = Downtime::AddDowntime(checkable, author, comment, startTime, endTime,
                fixed, triggerName, duration);
 
@@ -366,10 +375,6 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
        });
 
        /* Schedule downtime for all child objects. */
-       DowntimeChildOptions childOptions = DowntimeNoChildren;
-       if (params->Contains("child_options"))
-               childOptions = Downtime::ChildOptionsFromValue(HttpUtility::GetLastParameter(params, "child_options"));
-
        if (childOptions != DowntimeNoChildren) {
                /* 'DowntimeTriggeredChildren' schedules child downtimes triggered by the parent downtime.
                 * 'DowntimeNonTriggeredChildren' schedules non-triggered downtimes for all children.