Просмотр исходного кода

fix: clients ip address params trans (#5657)

* fix: clients ip address params trans
DDDHuang 4 лет назад
Родитель
Сommit
b1023d9733

+ 7 - 0
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
 %%--------------------------------------------------------------------

+ 3 - 3
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) ->