[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] get the connection events of clients

----- Original Message -----
> From: "Luca Tavanti" <luca.tavanti@xxxxxxxxxxxx>
> To: mosquitto-dev@xxxxxxxxxxx
> Sent: Wednesday, 12 September, 2018 16:01:35
> Subject: [mosquitto-dev] get the connection events of clients
>
> Dear all,
> 
> I'm trying to obtain information about the status of clients as they
> connect and disconnect, in order to track their status. I my deployment
> I have a restricted and known set of clients.
> I'm working on the server, so I have full access to the broker.
> 
> I would like to build this information automatically, without having the
> client send their status or last will (as I found it is often suggested
> on the web).
> 
> It seems to me that one possible way could be to enable
> "connection_messages" in the config and then parse the log.
> However, when trying it, I discovered that the line which I'm most
> interested in (which contains the clientID), is not written to the log
> in real time.
> For example:
> 1535990985: New connection from 213.188.207.137 on port 8844.
> 1535990985: New client connected from 213.188.207.137 as sys-a1b2c3 (c1,
> k60).
> 1535991025: Client sys-a1b2c3 disconnected.
> 
> The second line is generally flushed together with the third (or with
> any successive event that is logged).
> It is therefore very difficult to have a complete overview of the status
> of all clients in real time.
> 
> Can you suggest me a workaround for this issue?
> is there a way to force mosquitto to print the "New client connected
> from 213.188.207.137 as sys-a1b2c3 (c1, k60)" line in real time?
> 
> Alternatively, are you aware of a different method to get the real-time
> status of all clients (or the list of currently connected clients)?
> 
> Thanks in advance!
> 
> Luca


What is your authentication back-end? If you implement the mosquitto_plugin.h in C(++), you are free to program what you want. There is a function that is called to authorize clients upon first connection. You can log anything you want by writing the code for it.

The only issue is that you can't have two auth plugins, so you'd also have to write the code to replace whatever method you have now.