Use SyncSendMessage for remote endpoint and call ExecuteCommandAPIHandler for local endpoint

This commit is contained in:
Mattia Codato 2020-06-30 13:43:00 +02:00
parent 7077605880
commit 22dc2f2393

View File

@ -8,6 +8,7 @@
#include "icinga/checkcommand.hpp" #include "icinga/checkcommand.hpp"
#include "icinga/eventcommand.hpp" #include "icinga/eventcommand.hpp"
#include "icinga/notificationcommand.hpp" #include "icinga/notificationcommand.hpp"
#include "icinga/clusterevents.hpp"
#include "remote/apiaction.hpp" #include "remote/apiaction.hpp"
#include "remote/apilistener.hpp" #include "remote/apilistener.hpp"
#include "remote/pkiutility.hpp" #include "remote/pkiutility.hpp"
@ -661,9 +662,28 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
executions->Set(uuid, pending_execution); executions->Set(uuid, pending_execution);
checkable->SetExecutions(executions); checkable->SetExecutions(executions);
/* Create execution parameters */
Dictionary::Ptr execParams = new Dictionary();
execParams->Set("command_type", command_type);
execParams->Set("command", resolved_command);
execParams->Set("host", host->GetName());
if (service)
execParams->Set("service", service->GetShortName());
/*
* If the host/service object specifies the 'check_timeout' attribute,
* forward this to the remote endpoint to limit the command execution time.
*/
if (!checkable->GetCheckTimeout().IsEmpty())
execParams->Set("check_timeout", checkable->GetCheckTimeout());
execParams->Set("source", uuid);
execParams->Set("deadline", deadline);
bool local = endpointPtr == Endpoint::GetLocalEndpoint(); bool local = endpointPtr == Endpoint::GetLocalEndpoint();
if (local) { if (local) {
/* TODO */ MessageOrigin::Ptr origin = new MessageOrigin();
ClusterEvents::ExecuteCommandAPIHandler(origin, execParams);
} else { } else {
/* Broadcast the update */ /* Broadcast the update */
ApiListener::Ptr listener = ApiListener::GetInstance(); ApiListener::Ptr listener = ApiListener::GetInstance();
@ -681,34 +701,15 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
updateMessage->Set("method", "event::UpdateExecutions"); updateMessage->Set("method", "event::UpdateExecutions");
updateMessage->Set("params", updateParams); updateMessage->Set("params", updateParams);
MessageOrigin::Ptr origin = new MessageOrigin(); listener->SyncSendMessage(endpointPtr, updateMessage);
listener->RelayMessage(origin, checkable, updateMessage, true);
/* Execute command */ /* Execute command */
Dictionary::Ptr execMessage = new Dictionary(); Dictionary::Ptr execMessage = new Dictionary();
execMessage->Set("jsonrpc", "2.0"); execMessage->Set("jsonrpc", "2.0");
execMessage->Set("method", "event::ExecuteCommand"); execMessage->Set("method", "event::ExecuteCommand");
/* TODO set the right params */
Dictionary::Ptr execParams = new Dictionary();
execMessage->Set("params", execParams); execMessage->Set("params", execParams);
execParams->Set("command_type", command_type);
execParams->Set("command", resolved_command);
execParams->Set("host", host->GetName());
if (service)
execParams->Set("service", service->GetShortName());
/* listener->SyncSendMessage(endpointPtr, execMessage);
* If the host/service object specifies the 'check_timeout' attribute,
* forward this to the remote endpoint to limit the command execution time.
*/
if (!checkable->GetCheckTimeout().IsEmpty())
execParams->Set("check_timeout", checkable->GetCheckTimeout());
execParams->Set("source", uuid);
execParams->Set("deadline", deadline);
listener->RelayMessage(origin, checkable, execMessage, true);
} }
Dictionary::Ptr result = new Dictionary(); Dictionary::Ptr result = new Dictionary();