collectd: Support configuration of write_http plugin

write_http plugin is already built and shipped in
collectd-mod-write_http, 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_write_http() and
process_write_http_node(). First one just enables/disables the plugin.
The second one, in the spirit of the curl plugin, adds support for
populating multiple <Node> elements under <Plugin write_http> with
support for a few parameters. Those are:

* name. The name of the <Node>. Mandatory
* URL. Mandatory
* Format. Optional.
* User. Optional.
* Password. Optional.
* Timeout. Optional.
* BufferSize. Optional.

Signed-off-by: Alexandros Kosiaris <akosiaris@gmail.com>
This commit is contained in:
Alexandros Kosiaris 2022-06-20 19:07:01 +03:00 committed by Hannu Nyman
parent bed4479617
commit 033c19acd7
3 changed files with 59 additions and 0 deletions

View File

@ -78,6 +78,52 @@ process_curl_page() {
printf "\\t</Page>\n" >> "$COLLECTD_CONF"
}
process_write_http() {
printf "<Plugin write_http>\n" >> "$COLLECTD_CONF"
config_foreach process_write_http_node write_http_node
printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
}
process_write_http_node() {
local cfg="$1"
local name URL Format User Password Timeout BufferSize
config_get name "$cfg" name
[ -z "$name" ] && {
$LOG notice "No name option in config $cfg defined"
return 0
}
config_get URL "$cfg" URL
[ -z "$URL" ] && {
$LOG notice "No URL option in config $cfg defined"
return 0
}
config_get Format "$cfg" Format
config_get User "$cfg" User
config_get Password "$cfg" Password
config_get Timeout "$cfg" Timeout
config_get BufferSize "$cfg" BufferSize
printf "\\t<Node \"%s\">\n" "${name}" >> "$COLLECTD_CONF"
printf "\\t\\tURL \"%s\"\n" "${URL}" >> "$COLLECTD_CONF"
[ -z "$Format" ] || {
printf "\\t\\tFormat \"%s\"\n" "${Format}" >> "$COLLECTD_CONF"
}
[ -z "$User" ] || {
printf "\\t\\tUser \"%s\"\n" "${User}" >> "$COLLECTD_CONF"
}
[ -z "$Password" ] || {
printf "\\t\\tPassword \"%s\"\n" "${Password}" >> "$COLLECTD_CONF"
}
[ -z "$Timeout" ] || {
printf "\\t\\tTimeout \%s\n" "${Timeout}" >> "$COLLECTD_CONF"
}
[ -z "$BufferSize" ] || {
printf "\\t\\tBufferSize \%s\n" "${BufferSize}" >> "$COLLECTD_CONF"
}
printf "\\t</Node>\n" >> "$COLLECTD_CONF"
}
process_network() {
local cfg="$1"
@ -277,6 +323,10 @@ process_plugins() {
CONFIG_STRING=""
process_iptables
;;
write_http)
CONFIG_STRING=""
process_write_http
;;
*)
CONFIG_STRING=""
process_generic "$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"

View File

@ -213,3 +213,10 @@ config globals 'globals'
#config plugin 'vmem'
# option enable '0'
# option Verbose '0'
#
#config plugin 'write_http'
# option enable '0'
#
#config write_http_node
# option name 'foo'
# option URL 'http://example.org/post-collectd'

View File

@ -0,0 +1,2 @@
{
}