From e480eb785e701b43050d2b0cb870f62c16fbb26d Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 24 Oct 2018 11:00:24 +0200 Subject: [PATCH] Improve error handling for invalid child_options for API downtime actions fixes #6712 --- lib/icinga/apiactions.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 33b9d6f56..6d2fc3fc5 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -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. -- 2.40.0