fix(gateway_api): client ip and port as two fields when clients query

This commit is contained in:
JimMoen 2021-10-12 10:27:27 +08:00 committed by Rory Z
parent 6fb1d22e0c
commit a8bb2a60b0
2 changed files with 12 additions and 8 deletions

View File

@ -230,7 +230,7 @@ ms(username, X) ->
ms(zone, X) -> ms(zone, X) ->
#{clientinfo => #{zone => X}}; #{clientinfo => #{zone => X}};
ms(ip_address, X) -> ms(ip_address, X) ->
#{clientinfo => #{peerhost => X}}; #{clientinfo => #{peername => {X, '_'}}};
ms(conn_state, X) -> ms(conn_state, X) ->
#{conn_state => X}; #{conn_state => X};
ms(clean_start, X) -> ms(clean_start, X) ->
@ -276,7 +276,8 @@ format_channel_info({_, Infos, Stats}) ->
, {username, ClientInfo} , {username, ClientInfo}
, {proto_name, ConnInfo} , {proto_name, ConnInfo}
, {proto_ver, ConnInfo} , {proto_ver, ConnInfo}
, {ip_address, {peername, ConnInfo, fun peer_to_binary/1}} , {ip_address, {peername, ConnInfo, fun peer_to_binary_addr/1}}
, {port, {peername, ConnInfo, fun peer_to_port/1}}
, {is_bridge, ClientInfo, false} , {is_bridge, ClientInfo, false}
, {connected_at, , {connected_at,
{connected_at, ConnInfo, fun emqx_gateway_utils:unix_ts_to_rfc3339/1}} {connected_at, ConnInfo, fun emqx_gateway_utils:unix_ts_to_rfc3339/1}}
@ -341,13 +342,14 @@ key_get(K, M) when is_map(M) ->
key_get(K, L) when is_list(L) -> key_get(K, L) when is_list(L) ->
proplists:get_value(K, L). proplists:get_value(K, L).
peer_to_binary({Addr, Port}) -> -spec(peer_to_binary_addr(emqx_types:peername()) -> binary()).
AddrBinary = list_to_binary(inet:ntoa(Addr)), peer_to_binary_addr({Addr, _}) ->
PortBinary = integer_to_binary(Port),
<<AddrBinary/binary, ":", PortBinary/binary>>;
peer_to_binary(Addr) ->
list_to_binary(inet:ntoa(Addr)). list_to_binary(inet:ntoa(Addr)).
-spec(peer_to_port(emqx_types:peername()) -> inet:port_number()).
peer_to_port({_, Port}) ->
Port.
conn_state_to_connected(connected) -> true; conn_state_to_connected(connected) -> true;
conn_state_to_connected(_) -> false. conn_state_to_connected(_) -> false.
@ -536,6 +538,8 @@ properties_client() ->
<<"Protocol version used by the client">>} <<"Protocol version used by the client">>}
, {ip_address, string, , {ip_address, string,
<<"Client's IP address">>} <<"Client's IP address">>}
, {port, integer,
<<"Client's port">>}
, {is_bridge, boolean, , {is_bridge, boolean,
<<"Indicates whether the client is connectedvia bridge">>} <<"Indicates whether the client is connectedvia bridge">>}
, {connected_at, string, , {connected_at, string,

View File

@ -698,7 +698,7 @@ result_format_time_fun(Key, NClientInfoMap) ->
peername_dispart({Addr, Port}) -> peername_dispart({Addr, Port}) ->
AddrBinary = list_to_binary(inet:ntoa(Addr)), AddrBinary = list_to_binary(inet:ntoa(Addr)),
%% PortBinary = integer_to_binary(Port), %% PortBinary = integer_to_binary(Port),
{<<AddrBinary/binary>>, Port}. {AddrBinary, Port}.
format_authz_cache({{PubSub, Topic}, {AuthzResult, Timestamp}}) -> format_authz_cache({{PubSub, Topic}, {AuthzResult, Timestamp}}) ->
#{ access => PubSub, #{ access => PubSub,