Unify code to check if command exists

This commit is contained in:
Mattia Codato 2020-07-22 14:16:41 +02:00
parent 96dc349240
commit 4e3a38f320

View File

@ -225,10 +225,11 @@ 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) ||
command_type == "notification_command" && !NotificationCommand::GetByName(command)) {
ServiceState state = ServiceUnknown; ServiceState state = ServiceUnknown;
String output = "Check command '" + command + "' does not exist."; String output = command_type + " '" + command + "' does not exist.";
double now = Utility::GetTime(); double now = Utility::GetTime();
if (params->Contains("source")) { if (params->Contains("source")) {
@ -265,21 +266,8 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
} }
return; return;
} }
} else if (command_type == "event_command") {
if (!EventCommand::GetByName(command)) {
Log(LogWarning, "ClusterEvents")
<< "Event command '" << command << "' does not exist.";
return;
}
} else if (command_type == "notification_command") {
if (!NotificationCommand::GetByName(command)) {
Log(LogWarning, "ClusterEvents")
<< "Notification command '" << command << "' does not exist.";
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);