Check child endpoint versions and check child zone can access to the target endpoint

This commit is contained in:
Mattia Codato 2020-08-05 14:08:54 +02:00
parent a90068cc78
commit 7c004af6be
2 changed files with 54 additions and 2 deletions

View File

@ -817,12 +817,26 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
Zone::Ptr localZone = Zone::GetLocalZone();
for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
/* Fetch immediate child zone members */
if (zone->GetParent() == localZone) {
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointPtr->GetZone())) {
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
for (const Endpoint::Ptr& childEndpoint : endpoints) {
if (childEndpoint->GetIcingaVersion() < 21300) {
return ApiActions::CreateResult(400, "Endpoint '" + childEndpoint->GetName() + "' has version < 2.13.");
/* Update execution */
double now = Utility::GetTime();
pending_execution->Set("exit", 2);
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();
result->Set("checkable", checkable->GetName());
result->Set("execution", uuid);
return ApiActions::CreateResult(202, "Accepted", result);
}
}
}

View File

@ -633,6 +633,44 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
return Empty;
}
/* Check if the child endpoints have Icinga version >= 2.13 */
for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
/* Fetch immediate child zone members */
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointZone)) {
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
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"));
if (params->Contains("service"))
updateParams->Set("service", params->Get("service"));
updateParams->Set("executions", executionsToBroadcast);
Dictionary::Ptr updateMessage = new Dictionary();
updateMessage->Set("jsonrpc", "2.0");
updateMessage->Set("method", "event::UpdateExecutions");
updateMessage->Set("params", executionsToBroadcast);
listener->RelayMessage(nullptr, nullptr, updateMessage, true);
return Empty;
}
}
}
}
Dictionary::Ptr execMessage = new Dictionary();
execMessage->Set("jsonrpc", "2.0");
execMessage->Set("method", "event::ExecuteCommand");