enhancement(snmp_exporter): allows using multiple web listen addresses

Signed-off-by: Christian Krause <christian.krause@idiv.de>
This commit is contained in:
Christian Krause 2023-09-04 11:39:36 +02:00
parent dce2e959d9
commit 54d857d41b
No known key found for this signature in database
GPG key ID: 3CD613B9A8567F58
4 changed files with 40 additions and 4 deletions

View file

@ -3,5 +3,7 @@ provisioner:
inventory:
group_vars:
all:
snmp_exporter_web_listen_address: "127.0.0.1:9116"
snmp_exporter_web_listen_address:
- '127.0.0.1:9116'
- '127.0.1.1:9116'
snmp_exporter_config_file: ${MOLECULE_SCENARIO_DIRECTORY}/templates/snmp.yml

View file

@ -33,6 +33,9 @@ def test_service(host):
raise # Re-raise the original assertion error
def test_socket(host):
s = host.socket("tcp://127.0.0.1:9116")
assert s.is_listening
@pytest.mark.parametrize("sockets", [
"tcp://127.0.0.1:9116",
"tcp://127.0.1.1:9116",
])
def test_socket(host, sockets):
assert host.socket(sockets).is_listening

View file

@ -1,4 +1,26 @@
---
- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
snmp_exporter_web_listen_address is string
or
(
snmp_exporter_version is version('0.21.0', '>=') and
snmp_exporter_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[snmp_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Discover latest version
ansible.builtin.set_fact:
snmp_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/snmp_exporter/releases/latest', headers=_github_api_headers,

View file

@ -9,7 +9,16 @@ User=nobody
Group={{ 'nogroup' if ansible_os_family == 'Debian' else 'nobody' }}
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/snmp_exporter \
{% if snmp_exporter_version is version('0.21.0', '>=') and
snmp_exporter_web_listen_address is iterable and
snmp_exporter_web_listen_address is not mapping and
snmp_exporter_web_listen_address is not string %}
{% for address in snmp_exporter_web_listen_address %}
--web.listen-address={{ address }} \
{% endfor %}
{% else %}
--web.listen-address={{ snmp_exporter_web_listen_address }} \
{% endif %}
--log.level={{ snmp_exporter_log_level }} \
--config.file=/etc/snmp_exporter/snmp.yml