fix(API): Ensure that the node name is known

This commit is contained in:
firest 2022-11-01 15:49:02 +08:00
parent d0687c7aaa
commit 60492615ba
4 changed files with 52 additions and 31 deletions

View File

@ -131,12 +131,20 @@ monitor(get, #{query_string := QS, bindings := Bindings}) ->
end. end.
monitor_current(get, #{bindings := Bindings}) -> monitor_current(get, #{bindings := Bindings}) ->
NodeOrCluster = binary_to_atom(maps:get(node, Bindings, <<"all">>), utf8), RawNode = maps:get(node, Bindings, all),
case emqx_dashboard_monitor:current_rate(NodeOrCluster) of case emqx_misc:safe_to_existing_atom(RawNode, utf8) of
{ok, CurrentRate} -> {ok, NodeOrCluster} ->
{200, CurrentRate}; case emqx_dashboard_monitor:current_rate(NodeOrCluster) of
{badrpc, {Node, Reason}} -> {ok, CurrentRate} ->
Message = list_to_binary(io_lib:format("Bad node ~p, rpc failed ~p", [Node, Reason])), {200, CurrentRate};
{badrpc, {Node, Reason}} ->
Message = list_to_binary(
io_lib:format("Bad node ~p, rpc failed ~p", [Node, Reason])
),
{400, 'BAD_RPC', Message}
end;
{error, _} ->
Message = list_to_binary(io_lib:format("Bad node ~p", [RawNode])),
{400, 'BAD_RPC', Message} {400, 'BAD_RPC', Message}
end. end.

View File

@ -113,15 +113,19 @@ clients(get, #{
?QUERY_FUN ?QUERY_FUN
); );
Node0 -> Node0 ->
Node1 = binary_to_atom(Node0, utf8), case emqx_misc:safe_to_existing_atom(Node0) of
QStringWithoutNode = maps:without([<<"node">>], QString), {ok, Node1} ->
emqx_mgmt_api:node_query( QStringWithoutNode = maps:without([<<"node">>], QString),
Node1, emqx_mgmt_api:node_query(
QStringWithoutNode, Node1,
TabName, QStringWithoutNode,
?CLIENT_QSCHEMA, TabName,
?QUERY_FUN ?CLIENT_QSCHEMA,
) ?QUERY_FUN
);
{error, _} ->
{error, Node0, {badrpc, <<"invalid node">>}}
end
end, end,
case Result of case Result of
{error, page_limit_invalid} -> {error, page_limit_invalid} ->

View File

@ -648,15 +648,19 @@ list_clients(QString) ->
?QUERY_FUN ?QUERY_FUN
); );
Node0 -> Node0 ->
Node1 = binary_to_atom(Node0, utf8), case emqx_misc:safe_to_existing_atom(Node0) of
QStringWithoutNode = maps:without([<<"node">>], QString), {ok, Node1} ->
emqx_mgmt_api:node_query( QStringWithoutNode = maps:without([<<"node">>], QString),
Node1, emqx_mgmt_api:node_query(
QStringWithoutNode, Node1,
?CLIENT_QTAB, QStringWithoutNode,
?CLIENT_QSCHEMA, ?CLIENT_QTAB,
?QUERY_FUN ?CLIENT_QSCHEMA,
) ?QUERY_FUN
);
{error, _} ->
{error, Node0, {badrpc, <<"invalid node">>}}
end
end, end,
case Result of case Result of
{error, page_limit_invalid} -> {error, page_limit_invalid} ->

View File

@ -145,13 +145,18 @@ subscriptions(get, #{query_string := QString}) ->
?QUERY_FUN ?QUERY_FUN
); );
Node0 -> Node0 ->
emqx_mgmt_api:node_query( case emqx_misc:safe_to_existing_atom(Node0) of
binary_to_atom(Node0, utf8), {ok, Node1} ->
QString, emqx_mgmt_api:node_query(
?SUBS_QTABLE, Node1,
?SUBS_QSCHEMA, QString,
?QUERY_FUN ?SUBS_QTABLE,
) ?SUBS_QSCHEMA,
?QUERY_FUN
);
{error, _} ->
{error, Node0, {badrpc, <<"invalid node">>}}
end
end, end,
case Response of case Response of
{error, page_limit_invalid} -> {error, page_limit_invalid} ->