From 033c19acd7fb96cddd597f2c32ecf5963bc5ede6 Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Mon, 20 Jun 2022 19:07:01 +0300 Subject: [PATCH] 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 elements under with support for a few parameters. Those are: * name. The name of the . Mandatory * URL. Mandatory * Format. Optional. * User. Optional. * Password. Optional. * Timeout. Optional. * BufferSize. Optional. Signed-off-by: Alexandros Kosiaris --- utils/collectd/files/collectd.init | 50 +++++++++++++++++++ utils/collectd/files/collectd.uci | 7 +++ .../usr/share/collectd/plugin/write_http.json | 2 + 3 files changed, 59 insertions(+) create mode 100644 utils/collectd/files/usr/share/collectd/plugin/write_http.json diff --git a/utils/collectd/files/collectd.init b/utils/collectd/files/collectd.init index b8c0f368d..05e21e109 100644 --- a/utils/collectd/files/collectd.init +++ b/utils/collectd/files/collectd.init @@ -78,6 +78,52 @@ process_curl_page() { printf "\\t\n" >> "$COLLECTD_CONF" } +process_write_http() { + printf "\n" >> "$COLLECTD_CONF" + config_foreach process_write_http_node write_http_node + printf "\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\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\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" diff --git a/utils/collectd/files/collectd.uci b/utils/collectd/files/collectd.uci index a716e93f0..091dd9ae9 100644 --- a/utils/collectd/files/collectd.uci +++ b/utils/collectd/files/collectd.uci @@ -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' diff --git a/utils/collectd/files/usr/share/collectd/plugin/write_http.json b/utils/collectd/files/usr/share/collectd/plugin/write_http.json new file mode 100644 index 000000000..2c63c0851 --- /dev/null +++ b/utils/collectd/files/usr/share/collectd/plugin/write_http.json @@ -0,0 +1,2 @@ +{ +}