enhancement(blackbox_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 13:03:15 +02:00
parent 09f705ad00
commit 4897b20b47
No known key found for this signature in database
GPG key ID: 3CD613B9A8567F58
4 changed files with 36 additions and 5 deletions

View file

@ -3,10 +3,13 @@ provisioner:
inventory:
group_vars:
all:
blackbox_exporter_web_listen_address: "127.0.0.1:9000"
blackbox_exporter_web_listen_address:
- '127.0.0.1:9000'
- '127.0.1.1:9000'
blackbox_exporter_cli_flags:
log.level: "warn"
blackbox_exporter_configuration_modules:
tcp_connect:
prober: tcp
timeout: 5s
blackbox_exporter_version: 0.23.0

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:9000")
assert s.is_listening
@pytest.mark.parametrize("sockets", [
"tcp://127.0.0.1:9000",
"tcp://127.0.1.1:9000",
])
def test_socket(host, sockets):
assert host.socket(sockets).is_listening

View file

@ -20,10 +20,26 @@
ansible.builtin.package_facts:
when: "not 'packages' in ansible_facts"
- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
blackbox_exporter_web_listen_address is string
or
(
blackbox_exporter_version is version('0.23.0', '>=') and
blackbox_exporter_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- "':' in blackbox_exporter_web_listen_address"
- >-
[blackbox_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Discover latest version
ansible.builtin.set_fact:

View file

@ -16,7 +16,16 @@ ExecStart=/usr/local/bin/blackbox_exporter \
{% for flag, flag_value in blackbox_exporter_cli_flags.items() -%}
--{{ flag }}={{ flag_value }} \
{% endfor -%}
{% if blackbox_exporter_version is version('0.23.0', '>=') and
blackbox_exporter_web_listen_address is iterable and
blackbox_exporter_web_listen_address is not mapping and
blackbox_exporter_web_listen_address is not string %}
{% for address in blackbox_exporter_web_listen_address %}
--web.listen-address={{ address }}{{ " \\" if not loop.last else "" }}
{% endfor %}
{% else %}
--web.listen-address={{ blackbox_exporter_web_listen_address }}
{% endif %}
SyslogIdentifier=blackbox_exporter
KillMode=process