mirror of https://github.com/Icinga/icinga2.git
Unify code to check if command exists
This commit is contained in:
parent
96dc349240
commit
4e3a38f320
|
@ -225,61 +225,49 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
|
||||||
String command = params->Get("command");
|
String command = params->Get("command");
|
||||||
String command_type = params->Get("command_type");
|
String command_type = params->Get("command_type");
|
||||||
|
|
||||||
if (command_type == "check_command") {
|
if (command_type == "check_command" && !CheckCommand::GetByName(command) ||
|
||||||
if (!CheckCommand::GetByName(command)) {
|
command_type == "event_command" && !EventCommand::GetByName(command) ||
|
||||||
ServiceState state = ServiceUnknown;
|
command_type == "notification_command" && !NotificationCommand::GetByName(command)) {
|
||||||
String output = "Check command '" + command + "' does not exist.";
|
ServiceState state = ServiceUnknown;
|
||||||
double now = Utility::GetTime();
|
String output = command_type + " '" + command + "' does not exist.";
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
if (params->Contains("source")) {
|
if (params->Contains("source")) {
|
||||||
Dictionary::Ptr executedParams = new Dictionary();
|
Dictionary::Ptr executedParams = new Dictionary();
|
||||||
executedParams->Set("execution", params->Get("source"));
|
executedParams->Set("execution", params->Get("source"));
|
||||||
executedParams->Set("host", params->Get("host"));
|
executedParams->Set("host", params->Get("host"));
|
||||||
if (params->Contains("service"))
|
if (params->Contains("service"))
|
||||||
executedParams->Set("service", params->Get("service"));
|
executedParams->Set("service", params->Get("service"));
|
||||||
executedParams->Set("exit", state);
|
executedParams->Set("exit", state);
|
||||||
executedParams->Set("output", output);
|
executedParams->Set("output", output);
|
||||||
executedParams->Set("start", now);
|
executedParams->Set("start", now);
|
||||||
executedParams->Set("end", now);
|
executedParams->Set("end", now);
|
||||||
|
|
||||||
if (origin->IsLocal()) {
|
if (origin->IsLocal()) {
|
||||||
ClusterEvents::ExecutedCommandAPIHandler(origin, executedParams);
|
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->SyncSendMessage(sourceEndpoint, executedMessage);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
CheckResult::Ptr cr = new CheckResult();
|
Dictionary::Ptr executedMessage = new Dictionary();
|
||||||
cr->SetState(state);
|
executedMessage->Set("jsonrpc", "2.0");
|
||||||
cr->SetOutput(output);
|
executedMessage->Set("method", "event::ExecutedCommand");
|
||||||
cr->SetScheduleStart(now);
|
executedMessage->Set("params", executedParams);
|
||||||
cr->SetScheduleEnd(now);
|
|
||||||
cr->SetExecutionStart(now);
|
listener->SyncSendMessage(sourceEndpoint, executedMessage);
|
||||||
cr->SetExecutionEnd(now);
|
|
||||||
Dictionary::Ptr message = MakeCheckResultMessage(host, cr);
|
|
||||||
listener->SyncSendMessage(sourceEndpoint, message);
|
|
||||||
}
|
}
|
||||||
return;
|
} else {
|
||||||
}
|
CheckResult::Ptr cr = new CheckResult();
|
||||||
} else if (command_type == "event_command") {
|
cr->SetState(state);
|
||||||
if (!EventCommand::GetByName(command)) {
|
cr->SetOutput(output);
|
||||||
Log(LogWarning, "ClusterEvents")
|
cr->SetScheduleStart(now);
|
||||||
<< "Event command '" << command << "' does not exist.";
|
cr->SetScheduleEnd(now);
|
||||||
return;
|
cr->SetExecutionStart(now);
|
||||||
}
|
cr->SetExecutionEnd(now);
|
||||||
} else if (command_type == "notification_command") {
|
Dictionary::Ptr message = MakeCheckResultMessage(host, cr);
|
||||||
if (!NotificationCommand::GetByName(command)) {
|
listener->SyncSendMessage(sourceEndpoint, message);
|
||||||
Log(LogWarning, "ClusterEvents")
|
|
||||||
<< "Notification command '" << command << "' does not exist.";
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs->Set(command_type, params->Get("command"));
|
attrs->Set(command_type, command);
|
||||||
attrs->Set("command_endpoint", sourceEndpoint->GetName());
|
attrs->Set("command_endpoint", sourceEndpoint->GetName());
|
||||||
|
|
||||||
Deserialize(host, attrs, false, FAConfig);
|
Deserialize(host, attrs, false, FAConfig);
|
||||||
|
|
Loading…
Reference in New Issue