collectd: Support config of mqtt plugin
mqtt plugin is already built and shipped in collectd-mod-mqtt, however it is not possible to configure it via uci currently, instead having to rely on populating the config file manually. Add support by adding 2 functions, process_mqtt() and process_mqtt_block(). First one just enables/disables the plugin. The second one, in the spirit of the curl plugin, adds support for populating multiple <Publish> and <Subscribe> blocks under <Plugin mqtt> with support for some parameters. Those are: * blocktype. Publish or Subscribe. Mandatory * name. The name of the block. Mandatory * Host. Mandatory * Port. Optional * User. Optional * Password. Optional * ClientId. Optional * QoS. Optional * Prefix. Optional * Retain. Optional * StoreRates. Optional * CleanSession. Optional * Topic. Optional Bump PKG_RELEASE per comments in PR Signed-off-by: Alexandros Kosiaris <akosiaris@gmail.com>
This commit is contained in:
parent
89391d4213
commit
530ccbc90d
4 changed files with 110 additions and 1 deletions
|
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=collectd
|
PKG_NAME:=collectd
|
||||||
PKG_VERSION:=5.12.0
|
PKG_VERSION:=5.12.0
|
||||||
PKG_RELEASE:=43
|
PKG_RELEASE:=44
|
||||||
|
|
||||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
|
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
|
||||||
PKG_SOURCE_URL:=https://collectd.org/files/ \
|
PKG_SOURCE_URL:=https://collectd.org/files/ \
|
||||||
|
|
|
@ -124,6 +124,100 @@ process_write_http_node() {
|
||||||
printf "\\t</Node>\n" >> "$COLLECTD_CONF"
|
printf "\\t</Node>\n" >> "$COLLECTD_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_mqtt() {
|
||||||
|
printf "<Plugin mqtt>\n" >> "$COLLECTD_CONF"
|
||||||
|
config_foreach process_mqtt_block mqtt_block
|
||||||
|
printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
|
||||||
|
process_mqtt_block() {
|
||||||
|
local cfg="$1"
|
||||||
|
|
||||||
|
local blocktype name Host Port User Password ClientId QoS Prefix Retain StoreRates CleanSession Topic
|
||||||
|
|
||||||
|
config_get blocktype "$cfg" blocktype
|
||||||
|
[ -z "$blocktype" ] && {
|
||||||
|
$LOG notice "No blocktype option in config $cfg defined"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
config_get name "$cfg" name
|
||||||
|
[ -z "$name" ] && {
|
||||||
|
$LOG notice "No name option in config $cfg defined"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
config_get Host "$cfg" Host
|
||||||
|
[ -z "$Host" ] && {
|
||||||
|
$LOG notice "No Host option in config $cfg defined"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
config_get Port "$cfg" Port
|
||||||
|
config_get User "$cfg" User
|
||||||
|
config_get Password "$cfg" Password
|
||||||
|
config_get QoS "$cfg" QoS
|
||||||
|
config_get ClientId "$cfg" ClientId
|
||||||
|
config_get Prefix "$cfg" Prefix
|
||||||
|
[ -n "$Prefix" ] && [ "$blocktype" != "Publish" ] && {
|
||||||
|
$LOG notice "Prefix option in config $cfg defined under non Publish block"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
config_get Retain "$cfg" Retain
|
||||||
|
[ -n "$Retain" ] && [ "$blocktype" != "Publish" ] && {
|
||||||
|
$LOG notice "Retain option in config $cfg defined under non Publish block"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
config_get StoreRates "$cfg" StoreRates
|
||||||
|
[ -n "$StoreRates" ] && [ "$blocktype" != "Publish" ] && {
|
||||||
|
$LOG notice "StoreRates option in config $cfg defined under non Publish block"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
config_get CleanSession "$cfg" CleanSession
|
||||||
|
[ -n "$CleanSession" ] && [ "$blocktype" != "Subscribe" ] && {
|
||||||
|
$LOG notice "CleanSession option in config $cfg defined under non Subscribe block"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
config_get Topic "$cfg" Topic
|
||||||
|
[ -n "$Topic" ] && [ "$blocktype" != "Subscribe" ] && {
|
||||||
|
$LOG notice "Topic option in config $cfg defined under non Subscribe block"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
printf "\\t<%s \"%s\">\n" "${blocktype}" "${name}" >> "$COLLECTD_CONF"
|
||||||
|
[ -z "$Host" ] || {
|
||||||
|
printf "\\t\\tHost \"%s\"\n" "${Host}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$Port" ] || {
|
||||||
|
printf "\\t\\tPort \"%s\"\n" "${Port}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$User" ] || {
|
||||||
|
printf "\\t\\tUser \"%s\"\n" "${User}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$Password" ] || {
|
||||||
|
printf "\\t\\tPassword \"%s\"\n" "${Password}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$QoS" ] || {
|
||||||
|
printf "\\t\\tQoS %s\n" "${QoS}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$ClientId" ] || {
|
||||||
|
printf "\\t\\tClientId \"%s\"\n" "${ClientId}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$Prefix" ] || {
|
||||||
|
printf "\\t\\tPrefix \"%s\"\n" "${Prefix}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$Retain" ] || {
|
||||||
|
printf "\\t\\tRetain \"%s\"\n" "${Retain}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$StoreRates" ] || {
|
||||||
|
printf "\\t\\tStoreRates \"%s\"\n" "${StoreRates}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$CleanSession" ] || {
|
||||||
|
printf "\\t\\tCleanSession \"%s\"\n" "${CleanSession}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
[ -z "$Topic" ] || {
|
||||||
|
printf "\\t\\tTopic \"%s\"\n" "${Topic}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
printf "\\t</%s>\n" "${blocktype}" >> "$COLLECTD_CONF"
|
||||||
|
}
|
||||||
|
|
||||||
process_network() {
|
process_network() {
|
||||||
local cfg="$1"
|
local cfg="$1"
|
||||||
|
|
||||||
|
@ -407,6 +501,10 @@ process_plugins() {
|
||||||
CONFIG_STRING=""
|
CONFIG_STRING=""
|
||||||
process_write_http
|
process_write_http
|
||||||
;;
|
;;
|
||||||
|
mqtt)
|
||||||
|
CONFIG_STRING=""
|
||||||
|
process_mqtt
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
CONFIG_STRING=""
|
CONFIG_STRING=""
|
||||||
process_generic "$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"
|
process_generic "$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"
|
||||||
|
|
|
@ -221,3 +221,12 @@ config globals 'globals'
|
||||||
#config write_http_node
|
#config write_http_node
|
||||||
# option name 'foo'
|
# option name 'foo'
|
||||||
# option URL 'http://example.org/post-collectd'
|
# option URL 'http://example.org/post-collectd'
|
||||||
|
#
|
||||||
|
#config plugin 'mqtt'
|
||||||
|
# option enable '1'
|
||||||
|
#
|
||||||
|
#config mqtt_block
|
||||||
|
# option name 'foo'
|
||||||
|
# option blocktype 'Subscribe'
|
||||||
|
# option Host 'localhost'
|
||||||
|
# option Topic 'collectd/#'
|
||||||
|
|
2
utils/collectd/files/usr/share/collectd/plugin/mqtt.json
Normal file
2
utils/collectd/files/usr/share/collectd/plugin/mqtt.json
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
{
|
||||||
|
}
|
Loading…
Reference in a new issue