From 4803b33f89f71fe03b4ac545a94e1c2ef6938b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lisowski?= Date: Fri, 7 Feb 2025 18:54:09 +0100 Subject: [PATCH] Better sub inputs handling (#193) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Support for sub_inputs in extra plugins * fix: properly handle lists as TOML arrays - Updated the Jinja template to detect and serialize lists using |to_json, ensuring Telegraf interprets them correctly (e.g. names = ["item1","item2"]). - Removed fallback logic for single items, so we consistently treat all sub_input values as lists of dictionaries. --------- Co-authored-by: MichaƂ Lisowski --- README.md | 6 +++--- templates/telegraf-extra-plugin.conf.j2 | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e3ad453..f6b6609 100644 --- a/README.md +++ b/README.md @@ -342,13 +342,13 @@ sqs: - statistic_include = ["average"] sub_inputs: metrics: - - names = [ + - names: [ "ApproximateAgeOfOldestMessage", "ApproximateNumberOfMessagesVisible", ] metrics.dimensions: - - name = "QueueName" - - value = "*" + - name: "QueueName" + value: "*" ``` ## Dependencies diff --git a/templates/telegraf-extra-plugin.conf.j2 b/templates/telegraf-extra-plugin.conf.j2 index 9cb1acd..4d8cd86 100644 --- a/templates/telegraf-extra-plugin.conf.j2 +++ b/templates/telegraf-extra-plugin.conf.j2 @@ -56,10 +56,16 @@ {% endfor %} {% endif %} {% if item.value.sub_inputs is defined and item.value.sub_inputs is iterable %} -{% for sub_input, config in item.value.sub_inputs.items() %} -[[inputs.{{ item.value.plugin | default(item.key) }}.{{ sub_input }}]] -{% for items in config %} - {{ items }} +{% for sub_input_key, sub_input_list in item.value.sub_inputs.items() %} +{% for block in sub_input_list %} +[[inputs.{{ item.value.plugin | default(item.key) }}.{{ sub_input_key }}]] +{% for param_key, param_value in block.items() %} +{% if param_value is sequence and param_value is not string %} + {{ param_key }} = {{ param_value | to_json }} +{% else %} + {{ param_key }} = "{{ param_value }}" +{% endif %} +{% endfor %} {% endfor %} {% endfor %} {% endif %}