Get host by Deserialize

This commit is contained in:
Mattia Codato 2020-07-15 13:50:49 +02:00
parent 27f8bc5920
commit 4255fd9494
1 changed files with 20 additions and 14 deletions

View File

@ -104,24 +104,30 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
if (params->Contains("source")) {
String uuid = params->Get("source");
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) {
Log(LogCritical, "ApiListener") << "Host '" << params->Get("host") << "' not found.";
return;
}
Host::Ptr host = new Host();
Dictionary::Ptr attrs = new Dictionary();
attrs->Set("__name", params->Get("host"));
attrs->Set("type", "Host");
/*
* Override the check timeout if the parent caller provided the value. Compatible with older versions not
* passing this inside the cluster message.
* This happens with host/service command_endpoint agents and the 'check_timeout' attribute being specified.
*/
if (params->Contains("check_timeout"))
attrs->Set("check_timeout", params->Get("check_timeout"));
Deserialize(host, attrs, false, FAConfig);
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
host->SetExtension("agent_service_name", params->Get("service"));
if (!checkable) {
Log(LogCritical, "ApiListener") << "Checkable '" << params->Get("host")
<< "!" << params->Get("service") << "' not found.";
return;
}
attrs->Set(params->Get("command_type"), params->Get("command"));
attrs->Set("command_endpoint", sourceEndpoint->GetName());
Deserialize(host, attrs, false, FAConfig);
Checkable::Ptr checkable = host;
ObjectLock oLock (checkable);
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {