chore(audit): distinguish requests from rest_api or dashboard

This commit is contained in:
JianBo He 2023-09-27 20:21:10 +08:00
parent dd9938114c
commit 71acf121ba
2 changed files with 5 additions and 8 deletions

View File

@ -25,22 +25,19 @@ log(Meta0) ->
Duration = erlang:convert_time_unit(ReqEnd - ReqStart, native, millisecond), Duration = erlang:convert_time_unit(ReqEnd - ReqStart, native, millisecond),
Level = level(Method, Code, Duration), Level = level(Method, Code, Duration),
Username = maps:get(username, Meta0, <<"">>), Username = maps:get(username, Meta0, <<"">>),
From = from(maps:get(auth_type, Meta0, "")),
Meta1 = maps:without([req_start, req_end], Meta0), Meta1 = maps:without([req_start, req_end], Meta0),
Meta2 = Meta1#{time => logger:timestamp(), duration_ms => Duration}, Meta2 = Meta1#{time => logger:timestamp(), duration_ms => Duration},
Meta = emqx_utils:redact(Meta2), Meta = emqx_utils:redact(Meta2),
?AUDIT( ?AUDIT(
Level, Level,
rest_api, From,
Meta#{ Meta#{username => binary_to_list(Username), node => node()}
from => from(maps:get(auth_type, Meta0, "")),
username => binary_to_list(Username),
node => node()
}
), ),
ok. ok.
from(jwt_token) -> "dashboard"; from(jwt_token) -> "dashboard";
from(api_key) -> "aip_key"; from(api_key) -> "rest_api";
from(_) -> "unauthorized". from(_) -> "unauthorized".
level(get, _Code, _) -> debug; level(get, _Code, _) -> debug;

View File

@ -112,7 +112,7 @@ max_heap_size_warning(MF, Args) ->
log(_, {?MODULE, prompt_func}, [[{history, _}]]) -> log(_, {?MODULE, prompt_func}, [[{history, _}]]) ->
ok; ok;
log(IsAllow, MF, Args) -> log(IsAllow, MF, Args) ->
?AUDIT(warning, remote_console, #{ ?AUDIT(warning, shell, #{
time => logger:timestamp(), time => logger:timestamp(),
function => MF, function => MF,
args => pp_args(Args), args => pp_args(Args),