diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index e87b49f9a..96961edac 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -776,6 +776,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(); @@ -787,7 +788,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 7b3e237e7..94e61201b 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -607,7 +607,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; } @@ -1072,5 +1094,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; }