mirror of https://github.com/Icinga/icinga2.git
Set exit code 126 if endpoint doens't support the new executeCommand API
This commit is contained in:
parent
7c004af6be
commit
7474ab6de5
|
@ -824,13 +824,12 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
|
||||||
if (childEndpoint->GetIcingaVersion() < 21300) {
|
if (childEndpoint->GetIcingaVersion() < 21300) {
|
||||||
/* Update execution */
|
/* Update execution */
|
||||||
double now = Utility::GetTime();
|
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("output", "Endpoint '" + childEndpoint->GetName() + "' has version < 2.13.");
|
||||||
pending_execution->Set("start", now);
|
pending_execution->Set("start", now);
|
||||||
pending_execution->Set("end", now);
|
pending_execution->Set("end", now);
|
||||||
pending_execution->Remove("pending");
|
pending_execution->Remove("pending");
|
||||||
|
|
||||||
checkable->SetExecutions(executions);
|
|
||||||
listener->RelayMessage(origin, checkable, updateMessage, true);
|
listener->RelayMessage(origin, checkable, updateMessage, true);
|
||||||
|
|
||||||
Dictionary::Ptr result = new Dictionary();
|
Dictionary::Ptr result = new Dictionary();
|
||||||
|
|
|
@ -623,6 +623,7 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
|
||||||
if (!listener)
|
if (!listener)
|
||||||
return Empty;
|
return Empty;
|
||||||
|
|
||||||
|
if (params->Contains("endpoint")) {
|
||||||
Endpoint::Ptr execEndpoint = Endpoint::GetByName(params->Get("endpoint"));
|
Endpoint::Ptr execEndpoint = Endpoint::GetByName(params->Get("endpoint"));
|
||||||
if (execEndpoint != Endpoint::GetLocalEndpoint()) {
|
if (execEndpoint != Endpoint::GetLocalEndpoint()) {
|
||||||
|
|
||||||
|
@ -634,36 +635,35 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the child endpoints have Icinga version >= 2.13 */
|
/* Check if the child endpoints have Icinga version >= 2.13 */
|
||||||
for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
|
for (const Zone::Ptr &zone : ConfigType::GetObjectsByType<Zone>()) {
|
||||||
/* Fetch immediate child zone members */
|
/* Fetch immediate child zone members */
|
||||||
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointZone)) {
|
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointZone)) {
|
||||||
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
|
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
|
||||||
|
|
||||||
for (const Endpoint::Ptr& childEndpoint : endpoints) {
|
for (const Endpoint::Ptr &childEndpoint : endpoints) {
|
||||||
if (childEndpoint->GetIcingaVersion() < 21300) {
|
if (childEndpoint->GetIcingaVersion() < 21300) {
|
||||||
/* Update execution */
|
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
Dictionary::Ptr execution = new Dictionary();
|
Dictionary::Ptr executedParams = new Dictionary();
|
||||||
execution->Set("exit", 2);
|
executedParams->Set("execution", params->Get("source"));
|
||||||
execution->Set("output", "Endpoint '" + childEndpoint->GetName() + "' has version < 2.13.");
|
executedParams->Set("host", params->Get("host"));
|
||||||
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"));
|
|
||||||
if (params->Contains("service"))
|
if (params->Contains("service"))
|
||||||
updateParams->Set("service", params->Get("service"));
|
executedParams->Set("service", params->Get("service"));
|
||||||
updateParams->Set("executions", executionsToBroadcast);
|
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();
|
if (origin->IsLocal()) {
|
||||||
updateMessage->Set("jsonrpc", "2.0");
|
ClusterEvents::ExecutedCommandAPIHandler(origin, executedParams);
|
||||||
updateMessage->Set("method", "event::UpdateExecutions");
|
} else {
|
||||||
updateMessage->Set("params", executionsToBroadcast);
|
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;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
@ -677,9 +677,11 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
|
||||||
execMessage->Set("params", params);
|
execMessage->Set("params", params);
|
||||||
|
|
||||||
listener->RelayMessage(origin, endpointZone, execMessage, true);
|
listener->RelayMessage(origin, endpointZone, execMessage, true);
|
||||||
} else {
|
return Empty;
|
||||||
EnqueueCheck(origin, params);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EnqueueCheck(origin, params);
|
||||||
|
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue