From 951388797a00b7144c2ec1fb29d093212006e29a Mon Sep 17 00:00:00 2001 From: Mattia Codato Date: Mon, 3 Aug 2020 21:09:57 +0200 Subject: [PATCH] Forward the execute command through the zones --- lib/icinga/apiactions.cpp | 3 ++- lib/icinga/clusterevents.cpp | 40 +++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index e7d8acd88..977d0ee3e 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -806,6 +806,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, execParams->Set("source", uuid); execParams->Set("deadline", deadline); execParams->Set("macros", execMacros); + execParams->Set("endpoint", resolved_endpoint); /* Execute command */ bool local = endpointPtr == Endpoint::GetLocalEndpoint(); @@ -817,7 +818,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, execMessage->Set("method", "event::ExecuteCommand"); execMessage->Set("params", execParams); - listener->SyncSendMessage(endpointPtr, execMessage); + listener->RelayMessage(origin, checkable, execMessage, true); } Dictionary::Ptr result = new Dictionary(); diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp index 5817d8cc8..bc1d2d126 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -619,7 +619,29 @@ Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) { - EnqueueCheck(origin, params); + ApiListener::Ptr listener = ApiListener::GetInstance(); + if (!listener) + return Empty; + + Endpoint::Ptr execEndpoint = Endpoint::GetByName(params->Get("endpoint")); + if (execEndpoint != Endpoint::GetLocalEndpoint()) { + + Zone::Ptr endpointZone = execEndpoint->GetZone(); + Zone::Ptr localZone = Zone::GetLocalZone(); + + if (!endpointZone->IsChildOf(localZone)) { + return Empty; + } + + Dictionary::Ptr execMessage = new Dictionary(); + execMessage->Set("jsonrpc", "2.0"); + execMessage->Set("method", "event::ExecuteCommand"); + execMessage->Set("params", params); + + listener->RelayMessage(origin, endpointZone, execMessage, true); + } else { + EnqueueCheck(origin, params); + } return Empty; } @@ -1084,5 +1106,21 @@ Value ClusterEvents::UpdateExecutionsAPIHandler(const MessageOrigin::Ptr& origin newExecutions->CopyTo(executions); checkable->SetExecutions(executions); + ApiListener::Ptr listener = ApiListener::GetInstance(); + if (!listener) + return Empty; + + Dictionary::Ptr updateMessage = new Dictionary(); + updateMessage->Set("jsonrpc", "2.0"); + updateMessage->Set("method", "event::UpdateExecutions"); + updateMessage->Set("params", params); + + Zone::Ptr localZone = Zone::GetLocalZone(); + Zone::Ptr parentZone = localZone->GetParent(); + + if (localZone != parentZone) { + listener->RelayMessage(origin, parentZone, updateMessage, true); + } + return Empty; }