![]() |
![]()
| ![]() |
![]()
NAMEmsoak - consume messages from arbitrary MQTT brokers and subscriptions SYNOPSISmsoak [ -v ] configuration DESCRIPTIONmsoak is a utility with which to simultaneously subscribe to an arbitrary number of topics on any number of MQTT brokers and optionally modify or normalize received payloads before printing them out. This utility was created to back up to a central location messages received by a hand full of brokers; instead of launching (and having to monitor success of) a large number of mosquitto_sub(1) programs, msoak took on the job. msoak uses asynchronous connects to the MQTT brokers so that it can handle situations in which a broker may temporarily be unavailable even when msoak initially starts, and msoak embeds a Lua interpreter for which you can create scripts which act on messages received to, for example, trigger actions. msoak can be used with, say, tinylog(8) to create compressed archives of data. msoak my.config | tinylog -k 30 -s 1077936128 -z archive OPTIONS
CONFIGURATIONmsoak reads the configuration file using libconfig(3) utility functions. This is a short example:
The configuration consists of global settings and a list or array of servers, each with a number of settings. global variablesserver array
FormattingBy default, the received payload is printed to standard output, optionally prefixed by the message topic (if showtopic is true), and it is preceeded by the connection identifier if showid is true. If fmt is set, it contains a string with the name of a Lua function from the Lua script specified in the luascript global. this function is used to format the payload msoak receives; the return value of the function replaces the original payload and is printed out. If msoak can decode the payload into JSON (i.e. the message begins with a brace ({) and the JSON can be decoded), it will invoke the Lua function to obtain output.
The optional init() and exit() functions are invoked when msoak begins and ends respectively. The greet function is invoked for each message for which a server in the configuration file contains fmt = "greet". Lua functionsThere are a few variables and functions msoak implements which are available to the Lua scripts you use.
JSONWhen configured to use a Lua script file, msoak attempts to decode incoming JSON payloads and will pass the decoded JSON elements to the configured fmt function as a table with these additional elements in it
Note that if no luascript was specified and the payload contains JSON it will be dumped as is to stdout. ENVIRONMENTAny number of environment variables may be used by msoak if specified in passenv settings with the configuration. BUGSWhat's with the strange name? Just as I started working on this program I learned about sponge(1) and loved the name. The rest is history. Note that there are different versions of libconfig(3) floating around which may have effects on the syntax permitted in msoak's configuration file . AUTHORJan-Piet Mens, https://github.com/jpmens/msoak SEE ALSOmosquitto_sub(1), mqttwarn, sponge(1), strftime(1), tinylog(8)
|