From da82c1789163a8486142d7133e4072b62d7a9088 Mon Sep 17 00:00:00 2001 From: Mattia Codato Date: Fri, 26 Jun 2020 16:38:40 +0200 Subject: [PATCH] Call Endpoint::GetByName only once --- lib/icinga/apiactions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 1dca92f3d..a2002082a 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -588,7 +588,8 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, ); /* Check if endpoint exists */ - if (!Endpoint::GetByName(resolved_endpoint)) + Endpoint::Ptr endpointPtr = Endpoint::GetByName(resolved_endpoint); + if (!endpointPtr) return ApiActions::CreateResult(404, "Can't find a valid endpoint for '" + resolved_endpoint + "'."); /* Get command_type */ @@ -660,8 +661,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, executions->Set(uuid, pending_execution); checkable->SetExecutions(executions); - Endpoint::Ptr endpointPtr = Endpoint::GetByName(resolved_endpoint); - bool local = !endpointPtr || endpointPtr == Endpoint::GetLocalEndpoint(); + bool local = endpointPtr == Endpoint::GetLocalEndpoint(); if (local) { /* TODO */ } else {