2 Commits

Author SHA1 Message Date
8670792f6f Updated CHANGELOG.md on "2025-02-07 17:54:47" 2025-02-07 17:54:47 +00:00
4803b33f89 Better sub inputs handling (#193)
* 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 <mlisowski@sentient.ie>
2025-02-07 18:54:09 +01:00
7 changed files with 46 additions and 42 deletions

View File

@ -27,49 +27,46 @@ jobs:
fail-fast: false
matrix:
molecule_distro:
# - container: rocky8
# image: geerlingguy/docker-rockylinux8-ansible
- container: rocky8
image: geerlingguy/docker-rockylinux8-ansible
- container: rocky9
image: geerlingguy/docker-rockylinux9-ansible
- container: ubuntu2204
image: geerlingguy/docker-ubuntu2204-ansible:latest
- container: ubuntu2004
image: geerlingguy/docker-ubuntu2004-ansible:latest
# - container: ubuntu1804
# image: geerlingguy/docker-ubuntu1804-ansible:latest
- container: ubuntu1804
image: geerlingguy/docker-ubuntu1804-ansible:latest
- container: debian10
image: geerlingguy/docker-debian10-ansible:latest
- container: debian11
image: geerlingguy/docker-debian11-ansible:latest
steps:
- name: Check out code
uses: actions/checkout@v4
uses: actions/checkout@v1
- name: Set up Python 3.11
uses: actions/setup-python@v5
uses: actions/setup-python@v1
with:
python-version: 3.11.11
python-version: 3.11.10
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt
- name: Install test dependencies.
run: pip3 install ansible molecule molecule-plugins[docker] docker pytest testinfra
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run role tests on empty systems in check-mode
env:
MY_MOLECULE_CONTAINER: ${{ matrix.molecule_distro.container }}
MY_MOLECULE_IMAGE: ${{ matrix.molecule_distro.image }}
MY_MOLECULE_GROUP: ${{ matrix.molecule_distro.group }}
MY_MOLECULE_DOCKER_COMMAND: ${{ matrix.molecule_distro.command }}
run: molecule test -s empty-checkmode
run: >-
MY_MOLECULE_CONTAINER=${{ matrix.molecule_distro.container }}
MY_MOLECULE_IMAGE=${{ matrix.molecule_distro.image }}
MY_MOLECULE_GROUP=${{ matrix.molecule_distro.group }}
MY_MOLECULE_DOCKER_COMMAND=${{ matrix.molecule_distro.command }}
molecule test -s empty-checkmode
- name: Run role tests
env:
MY_MOLECULE_CONTAINER: ${{ matrix.molecule_distro.container }}
MY_MOLECULE_IMAGE: ${{ matrix.molecule_distro.image }}
MY_MOLECULE_GROUP: ${{ matrix.molecule_distro.group }}
MY_MOLECULE_DOCKER_COMMAND: ${{ matrix.molecule_distro.command }}
run: molecule test
run: >-
MY_MOLECULE_CONTAINER=${{ matrix.molecule_distro.container }}
MY_MOLECULE_IMAGE=${{ matrix.molecule_distro.image }}
MY_MOLECULE_GROUP=${{ matrix.molecule_distro.group }}
MY_MOLECULE_DOCKER_COMMAND=${{ matrix.molecule_distro.command }}
molecule test

View File

@ -6,6 +6,7 @@
**Merged pull requests:**
- Better sub inputs handling [\#193](https://github.com/dj-wasabi/ansible-telegraf/pull/193) ([lisuml](https://github.com/lisuml))
- Bump ansible-core from 2.18.0 to 2.18.1 [\#192](https://github.com/dj-wasabi/ansible-telegraf/pull/192) ([dependabot[bot]](https://github.com/apps/dependabot))
- Bump ansible-core from 2.16.8 to 2.18.0 [\#191](https://github.com/dj-wasabi/ansible-telegraf/pull/191) ([dependabot[bot]](https://github.com/apps/dependabot))
@ -181,7 +182,6 @@
- Some changes for fixing FreeBSD [\#101](https://github.com/dj-wasabi/ansible-telegraf/pull/101) ([dj-wasabi](https://github.com/dj-wasabi))
- basic FreeBSD support [\#100](https://github.com/dj-wasabi/ansible-telegraf/pull/100) ([langerma](https://github.com/langerma))
- Added the use\_proxy argument to use a proxy \(or not\) [\#98](https://github.com/dj-wasabi/ansible-telegraf/pull/98) ([dj-wasabi](https://github.com/dj-wasabi))
- Various small changes for molecule [\#97](https://github.com/dj-wasabi/ansible-telegraf/pull/97) ([dj-wasabi](https://github.com/dj-wasabi))
## [0.12.0](https://github.com/dj-wasabi/ansible-telegraf/tree/0.12.0) (2019-03-12)
@ -197,6 +197,7 @@
**Merged pull requests:**
- Various small changes for molecule [\#97](https://github.com/dj-wasabi/ansible-telegraf/pull/97) ([dj-wasabi](https://github.com/dj-wasabi))
- Add processors section in Telegraf config [\#94](https://github.com/dj-wasabi/ansible-telegraf/pull/94) ([ph4r5h4d](https://github.com/ph4r5h4d))
- Updated to Telegraf 1.10.0;Different installation methods [\#93](https://github.com/dj-wasabi/ansible-telegraf/pull/93) ([dj-wasabi](https://github.com/dj-wasabi))
- Updating Telegraf default to 1.9.5 [\#92](https://github.com/dj-wasabi/ansible-telegraf/pull/92) ([sdurrheimer](https://github.com/sdurrheimer))

View File

@ -342,13 +342,13 @@ sqs:
- statistic_include = ["average"]
sub_inputs:
metrics:
- names = [
- names: [
"ApproximateAgeOfOldestMessage",
"ApproximateNumberOfMessagesVisible",
]
metrics.dimensions:
- name = "QueueName"
- value = "*"
- name: "QueueName"
value: "*"
```
## Dependencies

View File

@ -1,4 +1,4 @@
---
- hosts: telegraf
roles:
- role: ../../ansible-telegraf
- role: ansible-telegraf

View File

@ -1,4 +1,4 @@
---
- hosts: telegraf
roles:
- role: ../../../ansible-telegraf
- role: ansible-telegraf

View File

@ -1,11 +1,11 @@
ansible==11.2.0
ansible-compat==25.1.2
ansible-core==2.18.2
ansible==9.7.0
ansible-compat==24.10.0
ansible-core==2.18.1
docker==7.1.0
molecule==25.2.0
molecule==6.0.3
molecule-docker==2.1.0
molecule-plugins==23.7.0
molecule-plugins==23.5.3
netaddr==1.3.0
pytest==8.3.4
pytest==8.3.3
pytest-testinfra==10.1.1
testinfra==6.0.0

View File

@ -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 %}