Set exit code 126 if endpoint doens't support the new executeCommand API

This commit is contained in:
Mattia Codato 2020-08-05 15:53:34 +02:00
parent 7c004af6be
commit 7474ab6de5
2 changed files with 48 additions and 47 deletions

View File

@ -824,13 +824,12 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
if (childEndpoint->GetIcingaVersion() < 21300) {
/* Update execution */
double now = Utility::GetTime();
pending_execution->Set("exit", 2);
pending_execution->Set("exit", 126);
pending_execution->Set("output", "Endpoint '" + childEndpoint->GetName() + "' has version < 2.13.");
pending_execution->Set("start", now);
pending_execution->Set("end", now);
pending_execution->Remove("pending");
checkable->SetExecutions(executions);
listener->RelayMessage(origin, checkable, updateMessage, true);
Dictionary::Ptr result = new Dictionary();

View File

@ -623,6 +623,7 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
if (!listener)
return Empty;
if (params->Contains("endpoint")) {
Endpoint::Ptr execEndpoint = Endpoint::GetByName(params->Get("endpoint"));
if (execEndpoint != Endpoint::GetLocalEndpoint()) {
@ -641,29 +642,28 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
for (const Endpoint::Ptr &childEndpoint : endpoints) {
if (childEndpoint->GetIcingaVersion() < 21300) {
/* Update execution */
double now = Utility::GetTime();
Dictionary::Ptr execution = new Dictionary();
execution->Set("exit", 2);
execution->Set("output", "Endpoint '" + childEndpoint->GetName() + "' has version < 2.13.");
execution->Set("start", now);
execution->Set("end", now);
Dictionary::Ptr executionsToBroadcast = new Dictionary();
executionsToBroadcast->Set(params->Get("source"), execution);
Dictionary::Ptr updateParams = new Dictionary();
updateParams->Set("host", params->Get("host"));
Dictionary::Ptr executedParams = new Dictionary();
executedParams->Set("execution", params->Get("source"));
executedParams->Set("host", params->Get("host"));
if (params->Contains("service"))
updateParams->Set("service", params->Get("service"));
updateParams->Set("executions", executionsToBroadcast);
executedParams->Set("service", params->Get("service"));
executedParams->Set("exit", 126);
executedParams->Set("output",
"Endpoint '" + childEndpoint->GetName() + "' has version < 2.13.");
executedParams->Set("start", now);
executedParams->Set("end", now);
Dictionary::Ptr updateMessage = new Dictionary();
updateMessage->Set("jsonrpc", "2.0");
updateMessage->Set("method", "event::UpdateExecutions");
updateMessage->Set("params", executionsToBroadcast);
if (origin->IsLocal()) {
ClusterEvents::ExecutedCommandAPIHandler(origin, executedParams);
} else {
Dictionary::Ptr executedMessage = new Dictionary();
executedMessage->Set("jsonrpc", "2.0");
executedMessage->Set("method", "event::ExecutedCommand");
executedMessage->Set("params", executedParams);
listener->RelayMessage(nullptr, nullptr, updateMessage, true);
listener->RelayMessage(nullptr, nullptr, executedMessage, true);
}
return Empty;
}
@ -677,9 +677,11 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
execMessage->Set("params", params);
listener->RelayMessage(origin, endpointZone, execMessage, true);
} else {
EnqueueCheck(origin, params);
return Empty;
}
}
EnqueueCheck(origin, params);
return Empty;
}