From: Michael Friedrich <michael.friedrich@icinga.com>
Date: Tue, 2 Jul 2019 09:15:43 +0000 (+0200)
Subject: API: Improve error handling for 'schedule-downtime' action
X-Git-Tag: v2.11.0-rc1~50^2
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ca38302fceeb05f99c703e1e66b234de996cbd5;p=icinga2

API: Improve error handling for 'schedule-downtime' action
---

diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp
index 757b37eca..9d7edbcc6 100644
--- a/lib/icinga/apiactions.cpp
+++ b/lib/icinga/apiactions.cpp
@@ -337,6 +337,16 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
 	String comment = HttpUtility::GetLastParameter(params, "comment");
 	double startTime = HttpUtility::GetLastParameter(params, "start_time");
 	double endTime = HttpUtility::GetLastParameter(params, "end_time");
+	double now = Utility::GetTime();
+
+	if (author.IsEmpty() || comment.IsEmpty())
+		return ApiActions::CreateResult(400, "Options 'author' and 'comment' must not be empty");
+
+	if (startTime < now || endTime < now)
+		return ApiActions::CreateResult(400, "Options 'start_time' and 'end_time' must be greater than current timestamp");
+
+	if (endTime < startTime)
+		return ApiActions::CreateResult(400, "Option 'end_time' must be greater than 'start_time'");
 
 	Host::Ptr host;
 	Service::Ptr service;