Send error as command execution result

This commit is contained in:
Mattia Codato 2020-07-20 08:18:53 +02:00
parent 461b4e2176
commit f59c60f85f
1 changed files with 19 additions and 16 deletions

View File

@ -180,21 +180,7 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
Log(LogWarning, "ApiListener") Log(LogWarning, "ApiListener")
<< "Ignoring command. '" << listener->GetName() << "' does not accept commands."; << "Ignoring command. '" << listener->GetName() << "' does not accept commands.";
Host::Ptr host = new Host(); String output = "Endpoint '" + Endpoint::GetLocalEndpoint()->GetName() + "' does not accept commands.";
Dictionary::Ptr attrs = new Dictionary();
attrs->Set("__name", params->Get("host"));
attrs->Set("type", "Host");
attrs->Set("enable_active_checks", false);
Deserialize(host, attrs, false, FAConfig);
if (params->Contains("service"))
host->SetExtension("agent_service_name", params->Get("service"));
CheckResult::Ptr cr = new CheckResult();
cr->SetState(ServiceUnknown);
cr->SetOutput("Endpoint '" + Endpoint::GetLocalEndpoint()->GetName() + "' does not accept commands.");
if (params->Contains("source")) { if (params->Contains("source")) {
Dictionary::Ptr executedParams = new Dictionary(); Dictionary::Ptr executedParams = new Dictionary();
@ -203,7 +189,8 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
if (params->Contains("service")) if (params->Contains("service"))
executedParams->Set("service", params->Get("service")); executedParams->Set("service", params->Get("service"));
double now = Utility::GetTime(); double now = Utility::GetTime();
executedParams->Set("error", cr->GetOutput()); executedParams->Set("exit", 126);
executedParams->Set("output", output);
executedParams->Set("start", now); executedParams->Set("start", now);
executedParams->Set("end", now); executedParams->Set("end", now);
@ -218,6 +205,22 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
listener->SyncSendMessage(sourceEndpoint, executedMessage); listener->SyncSendMessage(sourceEndpoint, executedMessage);
} }
} else { } else {
Host::Ptr host = new Host();
Dictionary::Ptr attrs = new Dictionary();
attrs->Set("__name", params->Get("host"));
attrs->Set("type", "Host");
attrs->Set("enable_active_checks", false);
Deserialize(host, attrs, false, FAConfig);
if (params->Contains("service"))
host->SetExtension("agent_service_name", params->Get("service"));
CheckResult::Ptr cr = new CheckResult();
cr->SetState(ServiceUnknown);
cr->SetOutput(output);
Dictionary::Ptr message = MakeCheckResultMessage(host, cr); Dictionary::Ptr message = MakeCheckResultMessage(host, cr);
listener->SyncSendMessage(sourceEndpoint, message); listener->SyncSendMessage(sourceEndpoint, message);
} }