From b1023d973344a62a391f03c97fd6c7cf86e625a0 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Mon, 6 Sep 2021 13:32:29 +0800 Subject: [PATCH] fix: clients ip address params trans (#5657) * fix: clients ip address params trans --- apps/emqx_management/src/emqx_mgmt_api.erl | 7 +++++++ apps/emqx_management/src/emqx_mgmt_api_clients.erl | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api.erl b/apps/emqx_management/src/emqx_mgmt_api.erl index 5a7b020d7..8cf2fa1cb 100644 --- a/apps/emqx_management/src/emqx_mgmt_api.erl +++ b/apps/emqx_management/src/emqx_mgmt_api.erl @@ -289,6 +289,7 @@ to_type_(V, atom) -> to_atom(V); to_type_(V, integer) -> to_integer(V); to_type_(V, timestamp) -> to_timestamp(V); to_type_(V, ip) -> aton(V); +to_type_(V, ip_port) -> to_ip_port(V); to_type_(V, _) -> V. to_atom(A) when is_atom(A) -> @@ -309,6 +310,12 @@ to_timestamp(B) when is_binary(B) -> aton(B) when is_binary(B) -> list_to_tuple([binary_to_integer(T) || T <- re:split(B, "[.]")]). +to_ip_port(IPAddress) -> + [IP0, Port0] = string:tokens(binary_to_list(IPAddress), ":"), + {ok, IP} = inet:parse_address(IP0), + Port = list_to_integer(Port0), + {IP, Port}. + %%-------------------------------------------------------------------- %% EUnits %%-------------------------------------------------------------------- diff --git a/apps/emqx_management/src/emqx_mgmt_api_clients.erl b/apps/emqx_management/src/emqx_mgmt_api_clients.erl index dd4df58a5..4b558eaae 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_clients.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_clients.erl @@ -45,7 +45,7 @@ [ {<<"node">>, atom} , {<<"username">>, binary} , {<<"zone">>, atom} - , {<<"ip_address">>, ip} + , {<<"ip_address">>, ip_port} , {<<"conn_state">>, atom} , {<<"clean_start">>, atom} , {<<"proto_name">>, binary} @@ -566,10 +566,10 @@ ms(username, X) -> #{clientinfo => #{username => X}}; ms(zone, X) -> #{clientinfo => #{zone => X}}; -ms(ip_address, X) -> - #{clientinfo => #{peerhost => X}}; ms(conn_state, X) -> #{conn_state => X}; +ms(ip_address, X) -> + #{conninfo => #{peername => X}}; ms(clean_start, X) -> #{conninfo => #{clean_start => X}}; ms(proto_name, X) ->