collectd: Support configuration of write_http plugin
authorAlexandros Kosiaris <redacted>
Mon, 20 Jun 2022 16:07:01 +0000 (19:07 +0300)
committerHannu Nyman <redacted>
Tue, 21 Jun 2022 15:30:04 +0000 (18:30 +0300)
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 <redacted>
utils/collectd/files/collectd.init
utils/collectd/files/collectd.uci
utils/collectd/files/usr/share/collectd/plugin/write_http.json [new file with mode: 0644]

index b8c0f368dc2023745f106077fb3b486e2d20fd37..05e21e109f78827602225df7bc16215d8ef506e1 100644 (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"
index a716e93f0f828e255644c2af5dcd53b72cb15d0f..091dd9ae9254d860839f94cf28490595f49ab2e8 100644 (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'
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 (file)
index 0000000..2c63c08
--- /dev/null
@@ -0,0 +1,2 @@
+{
+}
git clone https://git.99rst.org/PROJECT