Invalid params
This commit is contained in:
parent
8853e43275
commit
1f2cd40237
|
@ -197,12 +197,17 @@ cluster_join() ->
|
||||||
KeySpecs = [{'node', [{typecast, fun(Node) -> list_to_atom(Node) end}]}],
|
KeySpecs = [{'node', [{typecast, fun(Node) -> list_to_atom(Node) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, Node}], _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case emqttd_cluster:join(Node) of
|
Text = case get_value('node', Params) of
|
||||||
ok ->
|
undefined ->
|
||||||
["Join the cluster successfully.\n", cluster(["status"])];
|
io_lib:format("Invalid params node is undefined~n", []);
|
||||||
{error, Error} ->
|
Node ->
|
||||||
io_lib:format("Failed to join the cluster: ~p~n", [Error])
|
case emqttd_cluster:join(Node) of
|
||||||
|
ok ->
|
||||||
|
["Join the cluster successfully.\n", cluster(["status"])];
|
||||||
|
{error, Error} ->
|
||||||
|
io_lib:format("Failed to join the cluster: ~p~n", [Error])
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -227,12 +232,17 @@ cluster_remove() ->
|
||||||
KeySpecs = [{'node', [{typecast, fun(Node) -> list_to_atom(Node) end}]}],
|
KeySpecs = [{'node', [{typecast, fun(Node) -> list_to_atom(Node) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, Node}], _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case emqttd_cluster:remove(Node) of
|
Text = case get_value('node', Params) of
|
||||||
ok ->
|
undefined ->
|
||||||
["Remove the cluster successfully.\n", cluster(["status"])];
|
io_lib:format("Invalid params node is undefined~n", []);
|
||||||
{error, Error} ->
|
Node ->
|
||||||
io_lib:format("Failed to remove the cluster: ~p~n", [Error])
|
case emqttd_cluster:remove(Node) of
|
||||||
|
ok ->
|
||||||
|
["Remove the cluster successfully.\n", cluster(["status"])];
|
||||||
|
{error, Error} ->
|
||||||
|
io_lib:format("Failed to remove the cluster: ~p~n", [Error])
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -279,11 +289,16 @@ clients_kick() ->
|
||||||
KeySpecs = [{'client_id', [{typecast, fun(ClientId) -> list_to_binary(ClientId) end}]}],
|
KeySpecs = [{'client_id', [{typecast, fun(ClientId) -> list_to_binary(ClientId) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, ClientId}], _) ->
|
fun (_, Params, _) ->
|
||||||
Result = if_client(ClientId, fun(#mqtt_client{client_pid = Pid}) -> emqttd_client:kick(Pid) end),
|
case get_value('client_id', Params) of
|
||||||
case Result of
|
undefined ->
|
||||||
[ok] -> [clique_status:text(io_lib:format("Kick client_id: ~p successfully~n", [ClientId]))];
|
[clique_status:text(io_lib:format("Invalid params client_id is undefined~n", []))];
|
||||||
_ -> [clique_status:text("")]
|
ClientId ->
|
||||||
|
Result = if_client(ClientId, fun(#mqtt_client{client_pid = Pid}) -> emqttd_client:kick(Pid) end),
|
||||||
|
case Result of
|
||||||
|
[ok] -> [clique_status:text(io_lib:format("Kick client_id: ~p successfully~n", [ClientId]))];
|
||||||
|
_ -> [clique_status:text("")]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
||||||
|
@ -332,14 +347,18 @@ sessions_show() ->
|
||||||
KeySpecs = [{'client_id', [{typecast, fun(ClientId) -> list_to_binary(ClientId) end}]}],
|
KeySpecs = [{'client_id', [{typecast, fun(ClientId) -> list_to_binary(ClientId) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, ClientId}], _) ->
|
fun (_, Params, _) ->
|
||||||
|
case get_value('client_id', Params) of
|
||||||
case ets:lookup(mqtt_local_session, ClientId) of
|
undefined ->
|
||||||
[] ->
|
[clique_status:text(io_lib:format("Invalid params client_id is undefined~n", []))];
|
||||||
?PRINT_MSG("Not Found.~n"),
|
ClientId ->
|
||||||
[clique_status:table([])];
|
case ets:lookup(mqtt_local_session, ClientId) of
|
||||||
[SessInfo] ->
|
[] ->
|
||||||
[clique_status:table([print(SessInfo)])]
|
?PRINT_MSG("Not Found.~n"),
|
||||||
|
[clique_status:table([])];
|
||||||
|
[SessInfo] ->
|
||||||
|
[clique_status:table([print(SessInfo)])]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
||||||
|
@ -361,8 +380,13 @@ routes_show() ->
|
||||||
KeySpecs = [{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
KeySpecs = [{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, Topic}], _) ->
|
fun (_, Params, _) ->
|
||||||
[clique_status:table([print(mnesia:dirty_read(mqtt_route, Topic))])]
|
case get_value('topic', Params) of
|
||||||
|
undefined ->
|
||||||
|
[clique_status:text(io_lib:format("Invalid params topic is undefined~n", []))];
|
||||||
|
Topic ->
|
||||||
|
[clique_status:table([print(mnesia:dirty_read(mqtt_route, Topic))])]
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
||||||
|
|
||||||
|
@ -383,9 +407,14 @@ topics_show() ->
|
||||||
KeySpecs = [{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
KeySpecs = [{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, Topic}], _) ->
|
fun (_, Params, _) ->
|
||||||
Table = print(mnesia:dirty_read(mqtt_route, Topic)),
|
case get_value('client_id', Params) of
|
||||||
[clique_status:table([Table])]
|
undefined ->
|
||||||
|
[clique_status:text(io_lib:format("Invalid params topic is undefined~n", []))];
|
||||||
|
Topic ->
|
||||||
|
Table = print(mnesia:dirty_read(mqtt_route, Topic)),
|
||||||
|
[clique_status:table([Table])]
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
||||||
|
|
||||||
|
@ -407,14 +436,19 @@ subscriptions_show() ->
|
||||||
KeySpecs = [{'client_id', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
KeySpecs = [{'client_id', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, ClientId}], _) ->
|
fun (_, Params, _) ->
|
||||||
case ets:lookup(mqtt_subscription, ClientId) of
|
case get_value('client_id', Params) of
|
||||||
[] ->
|
undefined ->
|
||||||
?PRINT_MSG("Not Found.~n"),
|
[clique_status:text(io_lib:format("Invalid params client_id is undefined~n", []))];
|
||||||
[clique_status:table([])];
|
ClientId ->
|
||||||
Records ->
|
case ets:lookup(mqtt_subscription, ClientId) of
|
||||||
Table = [print(subscription, Subscription) || Subscription <- Records],
|
[] ->
|
||||||
[clique_status:table(Table)]
|
?PRINT_MSG("Not Found.~n"),
|
||||||
|
[clique_status:table([])];
|
||||||
|
Records ->
|
||||||
|
Table = [print(subscription, Subscription) || Subscription <- Records],
|
||||||
|
[clique_status:table(Table)]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
||||||
|
@ -432,11 +466,11 @@ subscriptions_subscribe() ->
|
||||||
QoS = get_value('qos', Params),
|
QoS = get_value('qos', Params),
|
||||||
Text = case {Topic, ClientId, QoS} of
|
Text = case {Topic, ClientId, QoS} of
|
||||||
{undefined, _, _} ->
|
{undefined, _, _} ->
|
||||||
io_lib:format("Invalid topic is undefined~n", []);
|
io_lib:format("Invalid params topic is undefined~n", []);
|
||||||
{_, undefined, _} ->
|
{_, undefined, _} ->
|
||||||
io_lib:format("Invalid client_id is undefined~n", []);
|
io_lib:format("Invalid params client_id is undefined~n", []);
|
||||||
{_, _, undefined} ->
|
{_, _, undefined} ->
|
||||||
io_lib:format("Invalid qos is undefined~n", []);
|
io_lib:format("Invalid params qos is undefined~n", []);
|
||||||
{_, _, _} ->
|
{_, _, _} ->
|
||||||
case emqttd:subscribe(Topic, ClientId, [{qos, QoS}]) of
|
case emqttd:subscribe(Topic, ClientId, [{qos, QoS}]) of
|
||||||
ok ->
|
ok ->
|
||||||
|
@ -456,10 +490,15 @@ subscriptions_del() ->
|
||||||
KeySpecs = [{'client_id', [{typecast, fun(ClientId) -> list_to_binary(ClientId) end}]}],
|
KeySpecs = [{'client_id', [{typecast, fun(ClientId) -> list_to_binary(ClientId) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, ClientId}], _) ->
|
fun (_, Params, _) ->
|
||||||
emqttd:subscriber_down(ClientId),
|
case get_value('client_id', Params) of
|
||||||
Text = io_lib:format("Client_id del subscriptions:~p successfully~n", [ClientId]),
|
undefined ->
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(io_lib:format("Invalid params client_id is undefined~n", []))];
|
||||||
|
ClientId ->
|
||||||
|
emqttd:subscriber_down(ClientId),
|
||||||
|
Text = io_lib:format("Client_id del subscriptions:~p successfully~n", [ClientId]),
|
||||||
|
[clique_status:text(Text)]
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
||||||
|
|
||||||
|
@ -475,11 +514,11 @@ subscriptions_unsubscribe() ->
|
||||||
QoS = get_value('qos', Params),
|
QoS = get_value('qos', Params),
|
||||||
Text = case {Topic, ClientId, QoS} of
|
Text = case {Topic, ClientId, QoS} of
|
||||||
{undefined, _, _} ->
|
{undefined, _, _} ->
|
||||||
io_lib:format("Invalid topic is undefined~n", []);
|
io_lib:format("Invalid params topic is undefined~n", []);
|
||||||
{_, undefined, _} ->
|
{_, undefined, _} ->
|
||||||
io_lib:format("Invalid client_id is undefined~n", []);
|
io_lib:format("Invalid params client_id is undefined~n", []);
|
||||||
{_, _, undefined} ->
|
{_, _, undefined} ->
|
||||||
io_lib:format("Invalid qos is undefined~n", []);
|
io_lib:format("Invalid params qos is undefined~n", []);
|
||||||
|
|
||||||
{_, _, _} ->
|
{_, _, _} ->
|
||||||
emqttd:unsubscribe(Topic, ClientId),
|
emqttd:unsubscribe(Topic, ClientId),
|
||||||
|
@ -505,12 +544,17 @@ plugins_load() ->
|
||||||
KeySpecs = [{'plugin_name', [{typecast, fun(PluginName) -> list_to_atom(PluginName) end}]}],
|
KeySpecs = [{'plugin_name', [{typecast, fun(PluginName) -> list_to_atom(PluginName) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, PluginName}], _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case emqttd_plugins:load(PluginName) of
|
Text = case get_value('plugin_name', Params) of
|
||||||
{ok, StartedApps} ->
|
undefined ->
|
||||||
io_lib:format("Start apps: ~p~nPlugin ~s loaded successfully.~n", [StartedApps, PluginName]);
|
io_lib:format("Invalid params plugin_name is undefined~n", []);
|
||||||
{error, Reason} ->
|
PluginName ->
|
||||||
io_lib:format("load plugin error: ~p~n", [Reason])
|
case emqttd_plugins:load(PluginName) of
|
||||||
|
{ok, StartedApps} ->
|
||||||
|
io_lib:format("Start apps: ~p~nPlugin ~s loaded successfully.~n", [StartedApps, PluginName]);
|
||||||
|
{error, Reason} ->
|
||||||
|
io_lib:format("load plugin error: ~p~n", [Reason])
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -521,12 +565,17 @@ plugins_unload() ->
|
||||||
KeySpecs = [{'plugin_name', [{typecast, fun(PluginName) -> list_to_atom(PluginName) end}]}],
|
KeySpecs = [{'plugin_name', [{typecast, fun(PluginName) -> list_to_atom(PluginName) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, PluginName}], _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case emqttd_plugins:unload(PluginName) of
|
Text = case get_value('plugin_name', Params) of
|
||||||
ok ->
|
undefined ->
|
||||||
io_lib:format("Plugin ~s unloaded successfully.~n", [PluginName]);
|
io_lib:format("Invalid params plugin_name is undefined~n", []);
|
||||||
{error, Reason} ->
|
PluginName ->
|
||||||
io_lib:format("unload plugin error: ~p~n", [Reason])
|
case emqttd_plugins:unload(PluginName) of
|
||||||
|
ok ->
|
||||||
|
io_lib:format("Plugin ~s unloaded successfully.~n", [PluginName]);
|
||||||
|
{error, Reason} ->
|
||||||
|
io_lib:format("unload plugin error: ~p~n", [Reason])
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -561,9 +610,9 @@ bridges_start() ->
|
||||||
fun (_, Params, _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case {get_value('snode', Params), get_value('topic', Params)} of
|
Text = case {get_value('snode', Params), get_value('topic', Params)} of
|
||||||
{undefined, _} ->
|
{undefined, _} ->
|
||||||
io_lib:format("Invalid snode is undefined~n", []);
|
io_lib:format("Invalid params snode is undefined~n", []);
|
||||||
{_, undefined} ->
|
{_, undefined} ->
|
||||||
io_lib:format("Invalid topic is undefined~n", []);
|
io_lib:format("Invalid params topic is undefined~n", []);
|
||||||
{SNode, Topic} ->
|
{SNode, Topic} ->
|
||||||
Opts = Params -- [{'snode', SNode}, {'topic', Topic}],
|
Opts = Params -- [{'snode', SNode}, {'topic', Topic}],
|
||||||
case emqttd_bridge_sup_sup:start_bridge(SNode, Topic, Opts) of
|
case emqttd_bridge_sup_sup:start_bridge(SNode, Topic, Opts) of
|
||||||
|
@ -586,9 +635,9 @@ bridges_stop() ->
|
||||||
fun (_, Params, _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case {get_value('snode', Params), get_value('topic', Params)} of
|
Text = case {get_value('snode', Params), get_value('topic', Params)} of
|
||||||
{undefined, _} ->
|
{undefined, _} ->
|
||||||
io_lib:format("Invalid snode is undefined~n", []);
|
io_lib:format("Invalid params snode is undefined~n", []);
|
||||||
{_, undefined} ->
|
{_, undefined} ->
|
||||||
io_lib:format("Invalid topic is undefined~n", []);
|
io_lib:format("Invalid params topic is undefined~n", []);
|
||||||
{SNode, Topic} ->
|
{SNode, Topic} ->
|
||||||
case emqttd_bridge_sup_sup:stop_bridge(SNode, Topic) of
|
case emqttd_bridge_sup_sup:stop_bridge(SNode, Topic) of
|
||||||
ok -> io_lib:format("bridge is stopped.~n", []);
|
ok -> io_lib:format("bridge is stopped.~n", []);
|
||||||
|
@ -724,7 +773,7 @@ trace_on() ->
|
||||||
topic ->
|
topic ->
|
||||||
trace_on(topic, get_value('topic', Params), get_value('log_file', Params));
|
trace_on(topic, get_value('topic', Params), get_value('log_file', Params));
|
||||||
Type ->
|
Type ->
|
||||||
io_lib:format("Invalid type: ~p error~n", [Type])
|
io_lib:format("Invalid params type: ~p error~n", [Type])
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -744,7 +793,7 @@ trace_off() ->
|
||||||
topic ->
|
topic ->
|
||||||
trace_off(topic, get_value('topic', Params));
|
trace_off(topic, get_value('topic', Params));
|
||||||
Type ->
|
Type ->
|
||||||
io_lib:format("Invalid type: ~p error~n", [Type])
|
io_lib:format("Invalid params type: ~p error~n", [Type])
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -862,7 +911,11 @@ status_usage() ->
|
||||||
["\n status info Show broker status\n"].
|
["\n status info Show broker status\n"].
|
||||||
|
|
||||||
listeners_usage() ->
|
listeners_usage() ->
|
||||||
["\n listeners info List listeners\n"].
|
["\n listeners info List listeners\n",
|
||||||
|
" listeners start Create and start a listener\n",
|
||||||
|
" listeners stop Stop accepting new connections for a running listener\n",
|
||||||
|
" listeners restart Restart accepting new connections for a stopped listener\n",
|
||||||
|
" listeners delete Delete a stopped listener"].
|
||||||
|
|
||||||
mnesia_usage() ->
|
mnesia_usage() ->
|
||||||
["\n mnesia info Mnesia system info\n"].
|
["\n mnesia info Mnesia system info\n"].
|
||||||
|
|
Loading…
Reference in New Issue