Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Online/offline client status #2973

Open
pr4u4t opened this issue Jan 8, 2024 · 0 comments
Open

[Feature Request] Online/offline client status #2973

pr4u4t opened this issue Jan 8, 2024 · 0 comments

Comments

@pr4u4t
Copy link

pr4u4t commented Jan 8, 2024

Hi,
recently I've been working on a project which involves mosquitto broker for handling large report message traffic. We have reached the point where we need a list of clients who are online or offline, I've came through issue list and found couple of threads with different proposals to solve that but none of them satisfied my needs. As I had some previous experience working with openresty(nginx+lua), lighttpd and haproxy which use Lua for internal scripting I've decided to implement such support in mosquitto broker as configurable feature. As for now It's vanilla version of Lua 5.1 which can be quickly replaced with luajit which should be even faster.

Feature has been added to dynamic_security plugin and handles init, cleanup plugin functions and following two events disconnect (added), auth. Each of this events and functions is handled by single script, to distinguish events in the script an array is passed to it. For init and cleanup functions containing only name "INIT"|"CLEANUP", for auth event name "CONNECTED" followed by clientd_id and client_addr and for disconnect event name "DISCONNECTED" followed by client_id. This enables making a reflection of mosquitto internal client list in fg. database engine of choice. init and cleanup functions set all clients state to offline and auth, disconnect events set client state online/offline for each client.

Feature is optional and can be enabled using config.mk or CMake build system. For the moment only thing that is missing is reloading Lua state using mosquitto_ctrl which can useful if changes has been made in lua handler while mosquitto is running as the script is only loaded once at plugin initialization for performance reasons. The code is available here:
mosquitto+lua

If you found this feature interesting please ping me for MR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant