Update mod_logxml to work with ejabberd git master
This commit is contained in:
parent
2b7bbd9535
commit
350d4d3884
|
@ -3,7 +3,7 @@
|
|||
|
||||
Homepage: http://www.ejabberd.im/mod_logxml
|
||||
Author: Badlop
|
||||
Module for ejabberd 0.7.5 or newer
|
||||
Module for ejabberd git master
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
|
@ -42,7 +42,6 @@ timezone:
|
|||
Default value: local
|
||||
show_ip:
|
||||
If the IP address of the local user should be logged to file.
|
||||
This option requires ejabberd 2.0.0 or newer, specifically SVN r772 (2007-05-21)
|
||||
Default value: false
|
||||
rotate_days:
|
||||
Rotate logs every X days
|
||||
|
@ -61,29 +60,28 @@ check_rotate_kpackets:
|
|||
Default value: 1
|
||||
|
||||
|
||||
|
||||
EXAMPLE CONFIGURATION
|
||||
---------------------
|
||||
|
||||
In ejabberd.cfg, in the modules section, add the module. For example:
|
||||
|
||||
{modules, [
|
||||
...
|
||||
{mod_logxml, [
|
||||
{stanza, [message, other]},
|
||||
{direction, [external]},
|
||||
{orientation, [send, recv]},
|
||||
{logdir, "/var/jabber/logs/"},
|
||||
{timezone, universal},
|
||||
{show_ip, false}, % To enable this option you need ejabberd 2.0.0 or newer
|
||||
{rotate_days, 1},
|
||||
{rotate_megs, 100},
|
||||
{rotate_kpackets, no},
|
||||
{check_rotate_kpackets, 1}
|
||||
]},
|
||||
...
|
||||
]}.
|
||||
In ejabberd.yml, in the modules section, add the module. For example:
|
||||
|
||||
modules:
|
||||
mod_logxml:
|
||||
stanza:
|
||||
- iq
|
||||
- other
|
||||
direction:
|
||||
- external
|
||||
orientation:
|
||||
- send
|
||||
- recv
|
||||
logdir: "/tmp/logs/"
|
||||
timezone: universal
|
||||
show_ip: false
|
||||
rotate_days: 1
|
||||
rotate_megs: 100
|
||||
rotate_kpackets: no
|
||||
check_rotate_kpackets: 1
|
||||
|
||||
|
||||
FORMAT OF XML
|
||||
|
|
|
@ -24,35 +24,35 @@
|
|||
%% -------------------
|
||||
|
||||
start(Host, Opts) ->
|
||||
Logdir = gen_mod:get_opt(logdir, Opts, "/tmp/jabberlogs/"),
|
||||
Logdir = gen_mod:get_opt(logdir, Opts, fun(A) -> A end, "/tmp/jabberlogs/"),
|
||||
|
||||
Rd = gen_mod:get_opt(rotate_days, Opts, 1),
|
||||
Rf = case gen_mod:get_opt(rotate_megs, Opts, 10) of
|
||||
Rd = gen_mod:get_opt(rotate_days, Opts, fun(A) -> A end, 1),
|
||||
Rf = case gen_mod:get_opt(rotate_megs, Opts, fun(A) -> A end, 10) of
|
||||
no -> no;
|
||||
Rf1 -> Rf1*1024*1024
|
||||
end,
|
||||
Rp = case gen_mod:get_opt(rotate_kpackets, Opts, 10) of
|
||||
Rp = case gen_mod:get_opt(rotate_kpackets, Opts, fun(A) -> A end, 10) of
|
||||
no -> no;
|
||||
Rp1 -> Rp1*1000
|
||||
end,
|
||||
RotateO = {Rd, Rf, Rp},
|
||||
CheckRKP = gen_mod:get_opt(check_rotate_kpackets, Opts, 1),
|
||||
CheckRKP = gen_mod:get_opt(check_rotate_kpackets, Opts, fun(A) -> A end, 1),
|
||||
|
||||
Timezone = gen_mod:get_opt(timezone, Opts, local),
|
||||
Timezone = gen_mod:get_opt(timezone, Opts, fun(A) -> A end, local),
|
||||
|
||||
Orientation = gen_mod:get_opt(orientation, Opts, [send, recv]),
|
||||
Stanza = gen_mod:get_opt(stanza, Opts, [iq, message, presence, other]),
|
||||
Direction = gen_mod:get_opt(direction, Opts, [internal, vhosts, external]),
|
||||
Orientation = gen_mod:get_opt(orientation, Opts, fun(A) -> A end, [send, recv]),
|
||||
Stanza = gen_mod:get_opt(stanza, Opts, fun(A) -> A end, [iq, message, presence, other]),
|
||||
Direction = gen_mod:get_opt(direction, Opts, fun(A) -> A end, [internal, vhosts, external]),
|
||||
FilterO = {
|
||||
{orientation, Orientation},
|
||||
{stanza, Stanza},
|
||||
{direction, Direction}},
|
||||
ShowIP = gen_mod:get_opt(show_ip, Opts, false),
|
||||
ShowIP = gen_mod:get_opt(show_ip, Opts, fun(A) -> A end, false),
|
||||
|
||||
ejabberd_hooks:add(user_send_packet, Host, ?MODULE, send_packet, 90),
|
||||
ejabberd_hooks:add(user_receive_packet, Host, ?MODULE, receive_packet, 90),
|
||||
register(gen_mod:get_module_proc(Host, ?PROCNAME),
|
||||
spawn(?MODULE, init, [Host, Logdir, RotateO, CheckRKP,
|
||||
spawn(?MODULE, init, [binary_to_list(Host), Logdir, RotateO, CheckRKP,
|
||||
Timezone, ShowIP, FilterO])).
|
||||
|
||||
stop(Host) ->
|
||||
|
@ -110,10 +110,10 @@ filter(FilterO, E) ->
|
|||
FilterO,
|
||||
{Orientation, From, To, Packet} = E,
|
||||
|
||||
{xmlelement, Stanza_str, _Attrs, _Els} = Packet,
|
||||
Stanza = list_to_atom(Stanza_str),
|
||||
{xmlel, Stanza_str, _Attrs, _Els} = Packet,
|
||||
Stanza = list_to_atom(binary_to_list(Stanza_str)),
|
||||
|
||||
Hosts_all = ejabberd_config:get_global_option(hosts),
|
||||
Hosts_all = ejabberd_config:get_global_option(hosts, fun(A) -> A end),
|
||||
{Host_local, Host_remote} = case Orientation of
|
||||
send -> {From#jid.lserver, To#jid.lserver};
|
||||
recv -> {To#jid.lserver, From#jid.lserver}
|
||||
|
@ -194,7 +194,7 @@ add_log(Io, Timezone, ShowIP, {Orientation, From, To, Packet}, _OSD) ->
|
|||
TimestampISO = get_now_iso(Timezone),
|
||||
io:fwrite(Io, "<packet or=\"~p\" ljid=\"~s\" ~sts=\"~s\">~s</packet>~n",
|
||||
[Orientation, jlib:jid_to_string(LocalJID), LocalIPS,
|
||||
TimestampISO, xml:element_to_string(Packet)]).
|
||||
TimestampISO, binary_to_list(xml:element_to_binary(Packet))]).
|
||||
|
||||
%% -------------------
|
||||
%% File
|
||||
|
@ -258,7 +258,7 @@ get_now_iso(Timezone) ->
|
|||
local -> calendar:now_to_local_time(now());
|
||||
universal -> calendar:now_to_universal_time(now())
|
||||
end,
|
||||
jlib:timestamp_to_iso(TimeStamp).
|
||||
binary_to_list(jlib:timestamp_to_iso(TimeStamp)).
|
||||
|
||||
calc_div(A, B) when is_integer(A) and is_integer(B) and B =/= 0 ->
|
||||
A/B;
|
||||
|
|
Loading…
Reference in New Issue