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"
printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
}
+process_network_server() {
+ local cfg="$1"
+ local SecurityLevel="$2"
+
+ local Username Password ResolveInterval
+
+ config_get Username "$cfg" Username
+ [ -z "$Username" ] && {
+ $LOG notice "SecurityLevel set to '$SecurityLevel' but no option Username found in config '$cfg'"
+ return 1
+ }
+ printf "\\t\\tUsername \"%s\"\n" "${Username}" >> "$COLLECTD_CONF"
+
+ config_get Password "$cfg" Password
+ [ -z "$Password" ] && {
+ $LOG notice "SecurityLevel set to '$SecurityLevel' but no option Password found in config '$cfg'"
+ return 2
+ }
+ printf "\\t\\tPassword \"%s\"\n" "${Password}" >> "$COLLECTD_CONF"
+
+ config_get ResolveInterval "$cfg" ResolveInterval
+ [ -z "$ResolveInterval" ] || {
+ printf "\\t\\tResolveInterval \"%s\"\n" "${ResolveInterval}" >> "$COLLECTD_CONF"
+ }
+}
+
+process_network_listen() {
+ local cfg="$1"
+
+ local auth_file="/tmp/collectd-auth-${cfg}.conf"
+ local auth_set
+
+ rm -rf "${auth_file}"
+ add_auth() {
+ echo "$1" >> "${auth_file}"
+ auth_set=1
+ }
+ config_list_foreach "$cfg" auth add_auth
+
+ [ -z "$auth_set" ] && {
+ $LOG notice "SecurityLevel set to '$SecurityLevel' but no list option auth found in config '$cfg'"
+ return 1
+ }
+
+ printf "\\t\\tAuthFile \"%s\"\n" "${auth_file}" >> "$COLLECTD_CONF"
+}
+
process_network_sections() {
local cfg="$1"
local section="$2"
- local host port output
+ local host port output rvalue SecurityLevel Interface
config_get host "$cfg" host
[ -z "$host" ] && {
config_get port "$cfg" port
if [ -z "$port" ]; then
- printf "\\t%s\n" "${output}" >> "$COLLECTD_CONF"
+ printf "\\t<%s>\n" "${output}" >> "$COLLECTD_CONF"
else
- printf "\\t%s \"%s\"\n" "${output}" "${port}" >> "$COLLECTD_CONF"
+ printf "\\t<%s \"%s\">\n" "${output}" "${port}" >> "$COLLECTD_CONF"
+ fi
+
+ config_get SecurityLevel "$cfg" SecurityLevel 'None'
+ [ -z "$SecurityLevel" ] || {
+ printf "\\t\\tSecurityLevel \"%s\"\n" "${SecurityLevel}" >> "$COLLECTD_CONF"
+ }
+
+ if [ "$SecurityLevel" != "None" ]; then
+ case "$section" in
+ server)
+ process_network_server "$cfg" "$SecurityLevel"
+ rvalue="$?"
+ [ "$rvalue" != 0 ] && return 0
+ ;;
+ listen)
+ process_network_listen "$cfg" "$SecurityLevel"
+ rvalue="$?"
+ [ "$rvalue" != 0 ] && return 0
+ ;;
+ esac
+ else
+ $LOG notice "SecurityLevel set to 'None' for '$cfg'"
+ fi
+
+ config_get Interface "$cfg" Interface
+ [ -z "$Interface" ] || {
+ printf "\\t\\tInterface \"%s\"\n" "${Interface}" >> "$COLLECTD_CONF"
+ }
+
+ if [ "$section" = "server" ]; then
+ printf "\\t</Server>\n" >> "$COLLECTD_CONF"
+ else
+ printf "\\t</Listen>\n" >> "$COLLECTD_CONF"
fi
}
CONFIG_STRING=""
process_iptables
;;
+ write_http)
+ CONFIG_STRING=""
+ process_write_http
+ ;;
*)
CONFIG_STRING=""
process_generic "$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"