diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index c3147fbc8..a4e910750 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -549,6 +549,10 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, Dictionary::Ptr resolvedMacros; bool useResolvedMacros; + if (params->Contains("macros") && !params->Get("macros").IsObjectType()) { + return ApiActions::CreateResult(400, "macros must be a dictionary"); + } + if (params->Contains("macros")) { resolvedMacros = HttpUtility::GetLastParameter(params, "macros"); useResolvedMacros = true; @@ -563,10 +567,6 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, useResolvedMacros ); - /* Check if resolved_endpoint is not empty */ - if (resolved_endpoint.IsEmpty()) - return ApiActions::CreateResult(400, "Endpoint must not be empty."); - /* Check if endpoint exists */ if (!Endpoint::GetByName(resolved_endpoint)) return ApiActions::CreateResult(404, "Can't find a valid endpoint for '" + resolved_endpoint + "'."); @@ -615,22 +615,16 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, } else if (command_type == "NotificationCommand") { if (!EventCommand::GetByName(resolved_command)) return ApiActions::CreateResult(400, "Command '" + resolved_command + "' is not of type '" + command_type + "'."); - } else - return ApiActions::CreateResult(400, "Invalid command_type '" + command_type + "'."); + } /* Get TTL param */ - double ttl = 0; /* FIXME default value? */ - if (params->Contains("ttl")) - ttl = HttpUtility::GetLastParameter(params, "ttl"); + if (!params->Contains("ttl")) + return ApiActions::CreateResult(400, "ttl is required"); + double ttl = HttpUtility::GetLastParameter(params, "ttl"); if (ttl <= 0) return ApiActions::CreateResult(400, "ttl must be greater than 0"); - /* Get wait param */ - bool wait = false; - if (params->Contains("wait")) - wait = HttpUtility::GetLastParameter(params, "wait"); - /* This generates a UUID */ String uuid = Utility::NewUniqueID(); @@ -695,8 +689,6 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, listener->SyncSendMessage(Endpoint::GetByName(resolved_endpoint), execMessage); - /* TODO handle the wait */ - Dictionary::Ptr result = new Dictionary(); result->Set(checkable->GetName(), uuid); return ApiActions::CreateResult(202, "Accepted", result);