Add mod_status/0 to show its current status in WebAdmin
This commit is contained in:
parent
8499366bcc
commit
e76b0877d6
|
@ -1,11 +1,14 @@
|
||||||
-module(ejabberd_observer_cli).
|
-module(ejabberd_observer_cli).
|
||||||
|
|
||||||
-export([start/0]).
|
-export([start/0, mod_status/0]).
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
application:set_env(observer_cli, plugins, plugins(), [{persistent, true}]),
|
application:set_env(observer_cli, plugins, plugins(), [{persistent, true}]),
|
||||||
observer_cli:start_plugin().
|
observer_cli:start_plugin().
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
"In an erlang shell run: ejabberd_observer_cli:start().".
|
||||||
|
|
||||||
plugins() ->
|
plugins() ->
|
||||||
[
|
[
|
||||||
#{
|
#{
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
%% gen_mod callbacks
|
%% gen_mod callbacks
|
||||||
-export([start/2, stop/1, reload/3, mod_options/1, depends/2, mod_doc/0]).
|
-export([start/2, stop/1, reload/3, mod_options/1, depends/2, mod_doc/0,
|
||||||
|
mod_status/0]).
|
||||||
%% hooks
|
%% hooks
|
||||||
-export([filter_packet/1]).
|
-export([filter_packet/1]).
|
||||||
|
|
||||||
|
@ -50,6 +51,9 @@ depends(_Host, _Opts) ->
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
"Isolation enabled".
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2, stop/1, depends/2, mod_opt_type/1, mod_options/1, mod_doc/0]).
|
-export([start/2, stop/1, depends/2, mod_opt_type/1, mod_options/1, mod_doc/0, mod_status/0]).
|
||||||
-export([init/1,
|
-export([init/1,
|
||||||
log_packet_send/1,
|
log_packet_send/1,
|
||||||
log_packet_receive/1]).
|
log_packet_receive/1]).
|
||||||
|
@ -289,3 +289,14 @@ mod_options(_Host) ->
|
||||||
{format, text}].
|
{format, text}].
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
Host = ejabberd_config:get_myname(),
|
||||||
|
gen_mod:get_module_proc(Host, ?PROCNAME) ! {call, self(), get_config},
|
||||||
|
Config = receive
|
||||||
|
{config, Result} ->
|
||||||
|
Result
|
||||||
|
end,
|
||||||
|
Format = Config#config.format,
|
||||||
|
Path = Config#config.path,
|
||||||
|
io_lib:format("Logging with format '~p' to path: ~s", [Format, Path]).
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2, stop/1, depends/2, mod_options/1, mod_opt_type/1, mod_doc/0]).
|
-export([start/2, stop/1, depends/2, mod_options/1, mod_opt_type/1, mod_doc/0, mod_status/0]).
|
||||||
-export([loop/3,
|
-export([loop/3,
|
||||||
reopen_log/1,
|
reopen_log/1,
|
||||||
failed_auth/3,
|
failed_auth/3,
|
||||||
|
@ -80,6 +80,16 @@ mod_options(_Host) ->
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
Host = ejabberd_config:get_myname(),
|
||||||
|
Pid = get_process_name(Host),
|
||||||
|
Pid ! {get_filename, self()},
|
||||||
|
Filename = receive
|
||||||
|
{filename, F} ->
|
||||||
|
F
|
||||||
|
end,
|
||||||
|
io_lib:format("Logging ~p to: ~s", [binary_to_list(Host), Filename]).
|
||||||
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% REQUEST HANDLERS
|
%%% REQUEST HANDLERS
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
@ -116,6 +126,9 @@ loop(Filename, File, Host) ->
|
||||||
reopenlog ->
|
reopenlog ->
|
||||||
File2 = reopen_file(File, Filename),
|
File2 = reopen_file(File, Filename),
|
||||||
loop(Filename, File2, Host);
|
loop(Filename, File2, Host);
|
||||||
|
{get_filename, Pid} ->
|
||||||
|
Pid ! {filename, Filename},
|
||||||
|
loop(Filename, File, Host);
|
||||||
stop ->
|
stop ->
|
||||||
close_file(File)
|
close_file(File)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
mod_opt_type/1,
|
mod_opt_type/1,
|
||||||
mod_options/1,
|
mod_options/1,
|
||||||
depends/2,
|
depends/2,
|
||||||
|
mod_status/0,
|
||||||
mod_doc/0]).
|
mod_doc/0]).
|
||||||
|
|
||||||
%% gen_server callbacks.
|
%% gen_server callbacks.
|
||||||
|
@ -108,6 +109,11 @@ depends(_Host, _Opts) ->
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
Proc = gen_mod:get_module_proc(global, ?MODULE),
|
||||||
|
{filename, Filename} = gen_server:call(Proc, get_filename, timer:seconds(15)),
|
||||||
|
io_lib:format("Logging to: ~s", [Filename]).
|
||||||
|
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
%% gen_server callbacks.
|
%% gen_server callbacks.
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
@ -125,6 +131,8 @@ init([_Host, Opts]) ->
|
||||||
{ok, #state{filename = Filename, iodevice = IoDevice}}.
|
{ok, #state{filename = Filename, iodevice = IoDevice}}.
|
||||||
|
|
||||||
-spec handle_call(_, {pid(), _}, state()) -> {noreply, state()}.
|
-spec handle_call(_, {pid(), _}, state()) -> {noreply, state()}.
|
||||||
|
handle_call(get_filename, From, State) ->
|
||||||
|
{reply, {filename, State#state.filename}, State};
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2, stop/1, depends/2, mod_options/1, mod_doc/0]).
|
-export([start/2, stop/1, depends/2, mod_options/1, mod_doc/0, mod_status/0]).
|
||||||
|
|
||||||
-export([process/2]).
|
-export([process/2]).
|
||||||
|
|
||||||
|
@ -237,3 +237,36 @@ mod_options(_Host) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
Host = ejabberd_config:get_myname(),
|
||||||
|
Url = case find_handler_port_path(any, ?MODULE) of
|
||||||
|
[] -> undefined;
|
||||||
|
[{ThisTls, Port, Path} | _] ->
|
||||||
|
Protocol = case ThisTls of
|
||||||
|
false -> <<"http">>;
|
||||||
|
true -> <<"https">>
|
||||||
|
end,
|
||||||
|
<<Protocol/binary,
|
||||||
|
"://",
|
||||||
|
Host/binary,
|
||||||
|
":",
|
||||||
|
(integer_to_binary(Port))/binary,
|
||||||
|
"/",
|
||||||
|
(str:join(Path, <<"/">>))/binary,
|
||||||
|
"/">>
|
||||||
|
end,
|
||||||
|
io_lib:format("Serving MUC logs in: ~s", [binary_to_list(Url)]).
|
||||||
|
|
||||||
|
find_handler_port_path(Tls, Module) ->
|
||||||
|
lists:filtermap(
|
||||||
|
fun({{Port, _, _},
|
||||||
|
ejabberd_http,
|
||||||
|
#{tls := ThisTls, request_handlers := Handlers}})
|
||||||
|
when (Tls == any) or (Tls == ThisTls) ->
|
||||||
|
case lists:keyfind(Module, 2, Handlers) of
|
||||||
|
false -> false;
|
||||||
|
{Path, Module} -> {true, {ThisTls, Port, Path}}
|
||||||
|
end;
|
||||||
|
(_) -> false
|
||||||
|
end, ets:tab2list(ejabberd_listener)).
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
depends/2,
|
depends/2,
|
||||||
split_line/1,
|
split_line/1,
|
||||||
process/2,
|
process/2,
|
||||||
|
mod_status/0,
|
||||||
mod_opt_type/1, mod_options/1, mod_doc/0]).
|
mod_opt_type/1, mod_options/1, mod_doc/0]).
|
||||||
|
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -189,3 +190,36 @@ mod_options(_Host) ->
|
||||||
{access_commands, []}].
|
{access_commands, []}].
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
Host = ejabberd_config:get_myname(),
|
||||||
|
Url = case find_handler_port_path(any, ?MODULE) of
|
||||||
|
[] -> undefined;
|
||||||
|
[{ThisTls, Port, Path} | _] ->
|
||||||
|
Protocol = case ThisTls of
|
||||||
|
false -> <<"http">>;
|
||||||
|
true -> <<"https">>
|
||||||
|
end,
|
||||||
|
<<Protocol/binary,
|
||||||
|
"://",
|
||||||
|
Host/binary,
|
||||||
|
":",
|
||||||
|
(integer_to_binary(Port))/binary,
|
||||||
|
"/",
|
||||||
|
(str:join(Path, <<"/">>))/binary,
|
||||||
|
"/">>
|
||||||
|
end,
|
||||||
|
io_lib:format("Awaiting HTTP POSTs in: ~s", [binary_to_list(Url)]).
|
||||||
|
|
||||||
|
find_handler_port_path(Tls, Module) ->
|
||||||
|
lists:filtermap(
|
||||||
|
fun({{Port, _, _},
|
||||||
|
ejabberd_http,
|
||||||
|
#{tls := ThisTls, request_handlers := Handlers}})
|
||||||
|
when (Tls == any) or (Tls == ThisTls) ->
|
||||||
|
case lists:keyfind(Module, 2, Handlers) of
|
||||||
|
false -> false;
|
||||||
|
{Path, Module} -> {true, {ThisTls, Port, Path}}
|
||||||
|
end;
|
||||||
|
(_) -> false
|
||||||
|
end, ets:tab2list(ejabberd_listener)).
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
depends/2,
|
depends/2,
|
||||||
mod_doc/0,
|
mod_doc/0,
|
||||||
mod_opt_type/1,
|
mod_opt_type/1,
|
||||||
|
mod_status/0,
|
||||||
mod_options/1]).
|
mod_options/1]).
|
||||||
%% Hooks:
|
%% Hooks:
|
||||||
-export([reopen_log/0,
|
-export([reopen_log/0,
|
||||||
|
@ -79,6 +80,9 @@ loop(Config) ->
|
||||||
file:close(Config#config.iodevice),
|
file:close(Config#config.iodevice),
|
||||||
{ok, IOD} = file:open(Config#config.filename, ?FILE_OPTS),
|
{ok, IOD} = file:open(Config#config.filename, ?FILE_OPTS),
|
||||||
loop(Config#config{iodevice = IOD});
|
loop(Config#config{iodevice = IOD});
|
||||||
|
{get_filename, Pid} ->
|
||||||
|
Pid ! {filename, Config#config.filename},
|
||||||
|
loop(Config);
|
||||||
stop ->
|
stop ->
|
||||||
file:close(Config#config.iodevice),
|
file:close(Config#config.iodevice),
|
||||||
exit(normal)
|
exit(normal)
|
||||||
|
@ -120,6 +124,11 @@ mod_options(_Host) ->
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
?PROCNAME ! {get_filename, self()},
|
||||||
|
Filename = receive {filename, F} -> F end,
|
||||||
|
io_lib:format("Logging to: ~s", [binary_to_list(Filename)]).
|
||||||
|
|
||||||
%% ---
|
%% ---
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2, stop/1, depends/2, mod_options/1, mod_doc/0]).
|
-export([start/2, stop/1, depends/2, mod_options/1, mod_doc/0, mod_status/0]).
|
||||||
-export([execute_system/1, execute_erlang/1]).
|
-export([execute_system/1, execute_erlang/1]).
|
||||||
-export([web_menu_node/3, web_page_node/5]).
|
-export([web_menu_node/3, web_page_node/5]).
|
||||||
|
|
||||||
|
@ -49,6 +49,9 @@ mod_options(_Host) ->
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
"Page available in WebAdmin -> Nodes -> your node -> Shell Commands".
|
||||||
|
|
||||||
%%-------------------
|
%%-------------------
|
||||||
%% Commands
|
%% Commands
|
||||||
%%-------------------
|
%%-------------------
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2, stop/1, depends/2, mod_opt_type/1, mod_options/1, mod_doc/0]).
|
-export([start/2, stop/1, depends/2, mod_opt_type/1, mod_options/1, mod_doc/0, mod_status/0]).
|
||||||
-export([loop/1, get_statistic/2,
|
-export([loop/1, get_statistic/2,
|
||||||
pre_uninstall/0,
|
pre_uninstall/0,
|
||||||
received_response/3,
|
received_response/3,
|
||||||
|
@ -100,6 +100,9 @@ mod_options(_Host) ->
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
"Pages 'Statistics Dx' available in WebAdmin, your Virtual Hosts and your Nodes".
|
||||||
|
|
||||||
%%%==================================
|
%%%==================================
|
||||||
%%%% Stats Server
|
%%%% Stats Server
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3,
|
terminate/2, code_change/3,
|
||||||
|
mod_status/0,
|
||||||
mod_opt_type/1, mod_options/1, depends/2, mod_doc/0]).
|
mod_opt_type/1, mod_options/1, depends/2, mod_doc/0]).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
|
@ -105,6 +106,39 @@ depends(_Host, _Opts) ->
|
||||||
|
|
||||||
mod_doc() -> #{}.
|
mod_doc() -> #{}.
|
||||||
|
|
||||||
|
mod_status() ->
|
||||||
|
Host = ejabberd_config:get_myname(),
|
||||||
|
Url = case find_handler_port_path(any, ?MODULE) of
|
||||||
|
[] -> undefined;
|
||||||
|
[{ThisTls, Port, Path} | _] ->
|
||||||
|
Protocol = case ThisTls of
|
||||||
|
false -> <<"http">>;
|
||||||
|
true -> <<"https">>
|
||||||
|
end,
|
||||||
|
<<Protocol/binary,
|
||||||
|
"://",
|
||||||
|
Host/binary,
|
||||||
|
":",
|
||||||
|
(integer_to_binary(Port))/binary,
|
||||||
|
"/",
|
||||||
|
(str:join(Path, <<"/">>))/binary,
|
||||||
|
"/">>
|
||||||
|
end,
|
||||||
|
io_lib:format("Serving Webpresence in: ~s", [binary_to_list(Url)]).
|
||||||
|
|
||||||
|
find_handler_port_path(Tls, Module) ->
|
||||||
|
lists:filtermap(
|
||||||
|
fun({{Port, _, _},
|
||||||
|
ejabberd_http,
|
||||||
|
#{tls := ThisTls, request_handlers := Handlers}})
|
||||||
|
when (Tls == any) or (Tls == ThisTls) ->
|
||||||
|
case lists:keyfind(Module, 2, Handlers) of
|
||||||
|
false -> false;
|
||||||
|
{Path, Module} -> {true, {ThisTls, Port, Path}}
|
||||||
|
end;
|
||||||
|
(_) -> false
|
||||||
|
end, ets:tab2list(ejabberd_listener)).
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
|
|
Loading…
Reference in New Issue