erszcz / ejabberd-trace

Easy tracing of users connected to ejabberd
11 stars 4 forks source link

ejabberd-trace

This is an extremely simple utility for easy tracing of connections made to ejabberd XMPP server.

In the future it might be expanded but just as well it might be abandoned due to proving to be useless.

The project is in rapid development - you have been warned. (Read: I don't care for API backwards compatibility for now).

Getting started

First, please start the application. This makes it auto-detect server string type in use.

> application:start(ejabberd_trace).

Tracing a connected user by JID

Trace a user who is connected to an ejabberd node:

> ejabberd_trace:user("asd@localhost/a-resource").
> % or
> ejabberd_trace:user("asd@localhost").

If you don't specify a resource and there are multiple available:

> ejabberd_trace:user("asd@localhost").
{error,{multiple_sessions,[{{"asd","localhost","psi"},
                            <0.327.0>},
                           {{"asd","localhost","x3"},<0.307.0>}]}}
> ejabberd_trace:user("asd@localhost/x3").

Tracing a user that is going to connect soon by JID

It's possible to trace a user who is not connected yet but will connect in a short period of time using only the JID.

It's useful in case you need to trace all communication (including connection initiation) happening between a c2s process and other parts of the system (including TCP connection) - this variant requires specifying the resource.

> ejabberd_trace:new_user("asd@localhost/x4").

Keep in mind this might be heavy on the system - until it's known which of the connected processes is the one you want to trace all newly connecting c2s processes are traced and the traces cached. Once it's known (by inspecting the XMPP stream) which process is the one to be traced its trace cache is flushed to the trace handler; the rest of the trace cache is discarded.

Display c2s process state by JID

> ejabberd_trace:state("asd@localhost").

Display incoming/outgoing XMPP streams for a given user

This gives a complete pretty-printed log of the whole client to server connection for a single full JID:

> ejabberd_trace:new_user("alice@localhost/escalus-default-resource",
                          ejabberd_trace_filter:stream(),
                          fun ejabberd_trace_format:stream/2).

Example output:

in :
<stream:stream to='localhost' version='1.0' xml:lang='en' xmlns='jabber:client'
               xmlns:stream='http://etherx.jabber.org/streams'>

out :
<?xml version='1.0'?>
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'
               id='1217298371' from='localhost' version='1.0' xml:lang='en'>

out :
<stream:features>
  <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
    <mechanism>DIGEST-MD5</mechanism>
    <mechanism>PLAIN</mechanism>
    <mechanism>SCRAM-SHA-1</mechanism>
  </mechanisms>
  <c ver='mfN6SdQ3DGO7/QUHHftElVDFZ7k='
     node='http://www.process-one.net/en/ejabberd/'
     hash='sha-1'
     xmlns='http://jabber.org/protocol/caps'/>
  <register xmlns='http://jabber.org/features/iq-register'/>
  <sm xmlns='urn:xmpp:sm:3'/>
</stream:features>

in :
<auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>AGFsaWNlAG1ha290YQ==</auth>

out :
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

...

Filters

It's possible to filter the traces caught for the traced process. The available filters are:

ToDo