From f0fe777eb0657b1dce81b0dd931803878d1ad078 Mon Sep 17 00:00:00 2001 From: Mattia Codato Date: Tue, 30 Jun 2020 17:50:08 +0200 Subject: [PATCH] Use RelayMessage to broadcast the updated executions --- lib/icinga/apiactions.cpp | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index b148f4bf7..b6b720abb 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -629,6 +629,25 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, executions->Set(uuid, pending_execution); checkable->SetExecutions(executions); + /* Broadcast the update */ + ApiListener::Ptr listener = ApiListener::GetInstance(); + if (!listener) + return ApiActions::CreateResult(404, "No ApiListener instance available."); + + Dictionary::Ptr updateParams = new Dictionary(); + updateParams->Set("host", host->GetName()); + if (service) + updateParams->Set("service", service->GetShortName()); + updateParams->Set("executions", executions); + + Dictionary::Ptr updateMessage = new Dictionary(); + updateMessage->Set("jsonrpc", "2.0"); + updateMessage->Set("method", "event::UpdateExecutions"); + updateMessage->Set("params", updateParams); + + MessageOrigin::Ptr origin = new MessageOrigin(); + listener->RelayMessage(origin, checkable, updateMessage, true); + /* Create execution parameters */ Dictionary::Ptr execParams = new Dictionary(); execParams->Set("command_type", command_type); @@ -647,30 +666,11 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, execParams->Set("source", uuid); execParams->Set("deadline", deadline); + /* Execute command */ bool local = endpointPtr == Endpoint::GetLocalEndpoint(); if (local) { - MessageOrigin::Ptr origin = new MessageOrigin(); ClusterEvents::ExecuteCommandAPIHandler(origin, execParams); } else { - /* Broadcast the update */ - ApiListener::Ptr listener = ApiListener::GetInstance(); - if (!listener) - return ApiActions::CreateResult(404, "No ApiListener instance available."); - - Dictionary::Ptr updateParams = new Dictionary(); - updateParams->Set("host", host->GetName()); - if (service) - updateParams->Set("service", service->GetShortName()); - updateParams->Set("executions", executions); - - Dictionary::Ptr updateMessage = new Dictionary(); - updateMessage->Set("jsonrpc", "2.0"); - updateMessage->Set("method", "event::UpdateExecutions"); - updateMessage->Set("params", updateParams); - - listener->SyncSendMessage(endpointPtr, updateMessage); - - /* Execute command */ Dictionary::Ptr execMessage = new Dictionary(); execMessage->Set("jsonrpc", "2.0"); execMessage->Set("method", "event::ExecuteCommand");