collectd: add network uci config
authorFlorian Eckert <fe@dev.tdt.de>
Mon, 16 Sep 2019 13:48:02 +0000 (15:48 +0200)
committerHannu Nyman <hannu.nyman@iki.fi>
Sat, 30 Nov 2019 17:15:12 +0000 (19:15 +0200)
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
(cherry-picked for 19.07)
Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
utils/collectd/files/collectd.init
utils/collectd/files/collectd.uci
utils/collectd/files/usr/share/collectd/plugin/network.json [new file with mode: 0644]

index a299200155aabcea9283fa3879ed2e321fdcfb79..845d33975327bbb43b10890ce2e529733572ba58 100644 (file)
@@ -73,6 +73,61 @@ process_curl_page() {
        printf "\\t</Page>\n" >> "$COLLECTD_CONF"
 }
 
+process_network() {
+       local cfg="$1"
+
+       local TimeToLive Forward CacheFlush
+
+       printf "<Plugin network>\n" >> "$COLLECTD_CONF"
+       config_foreach process_network_sections network_listen "listen"
+       config_foreach process_network_sections network_server "server"
+
+       config_get TimeToLive "$cfg" TimeToLive
+       [ -z "$TimeToLive" ] || {
+               printf "\\tTimeToLive %s\n" "${TimeToLive}" >> "$COLLECTD_CONF"
+       }
+
+       config_get CacheFlush "$cfg" CacheFlush
+       [ -z "$CacheFlush" ] || {
+               printf "\\tCacheFlush %s\n" "${CacheFlush}" >> "$COLLECTD_CONF"
+       }
+
+       config_get_bool Forward "$cfg" Forward
+       if [ "$value" = "0" ]; then
+               printf "\\tForward false\n" >> "$COLLECTD_CONF"
+       else
+               printf "\\tForward true\n" >> "$COLLECTD_CONF"
+       fi
+
+       printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
+}
+
+process_network_sections() {
+       local cfg="$1"
+       local section="$2"
+
+       local host port output
+
+       config_get host "$cfg" host
+       [ -z "$host" ] && {
+               $LOG notice "No host option in config $cfg defined"
+               return 0
+       }
+
+       if [ "$section" = "server" ]; then
+               output="Server \"$host\""
+       else
+               output="Listen \"$host\""
+       fi
+
+       config_get port "$cfg" port
+       if [ -z "$port" ]; then
+               printf "\\t%s\n" "${output}" >> "$COLLECTD_CONF"
+       else
+               printf "\\t%s \"%s\"\n" "${output}" "${port}" >> "$COLLECTD_CONF"
+       fi
+}
+
 CONFIG_LIST=""
 add_list_option() {
        local value="$1"
@@ -172,6 +227,10 @@ process_plugins() {
                        CONFIG_STRING=""
                        process_curl
                        ;;
+               network)
+                       CONFIG_STRING=""
+                       process_network "$cfg"
+                       ;;
                *)
                        CONFIG_STRING=""
                        process_generic "$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"
index 22cade912138ccf9f6481f318aa1b75a3419db65..5df40728bd5337d1151564b6742a58af0164385c 100644 (file)
@@ -108,6 +108,20 @@ config globals 'globals'
 #      list VerboseInterface 'br-lan'
 #      list QDisc 'br-lan'
 
+#config plugin 'network'
+#      option enable '1'
+#      option TimeToLive '128'
+#      option Forward '1'
+#      option CacheFlush '86400'
+
+#config network_listen
+#      option host '0.0.0.0'
+#      option port '25826'
+
+#config network_server
+#      option host '1.1.1.1'
+#      option port '25826'
+
 #config plugin 'nut'
 #      option enable '0'
 #      option UPS 'myupsname'
diff --git a/utils/collectd/files/usr/share/collectd/plugin/network.json b/utils/collectd/files/usr/share/collectd/plugin/network.json
new file mode 100644 (file)
index 0000000..2c63c08
--- /dev/null
@@ -0,0 +1,2 @@
+{
+}