Add target_files and relabel_configs options for blackbox and snmp jobs

This commit is contained in:
Julian Rother 2025-02-13 00:44:30 +01:00
parent b99318f2b4
commit eacbae416c
Signed by: julian
GPG key ID: C19B924C0CD13341

View file

@ -29,12 +29,21 @@
{% endfor %}
params:
module: [{{ job.module }}]
{% if job.targets|d(False) %}
static_configs:
- targets:
{% for t in job.targets %}
- {{ t }}
{% endfor %}
labels: {{ merged_prometheus_labels|combine(job.labels|d({}))|to_json }}
{% endif %}
{% if job.target_files|d(False) %}
file_sd_configs:
- files:
{% for path in job.target_files %}
- {{ path }}
{% endfor %}
{% endif %}
tls_config:
ca_file: /etc/prometheus/targetcerts/{{ inventory_hostname }}.crt
cert_file: /etc/ssl/prometheus_scraper.crt
@ -52,6 +61,9 @@
target_label: module
- target_label: __address__
replacement: {{ inventory_hostname }}:{{ prometheus_agent.scrapers[item].blackbox }}
{% for relabel_config in job.relabel_configs|d([]) %}
- {{ relabel_config|tojson }}
{% endfor %}
{% endfor %}
{% endif %}
@ -61,14 +73,23 @@
- job_name: "prometheus-agent - snmp - {{ j }} : {{ inventory_hostname }}"
scheme: https
metrics_path: /snmp
{% if job.targets|d(False) %}
static_configs:
- targets:
{% for target in job.targets %}
- {{ target }}
{% endfor %}
labels: {{ merged_prometheus_labels|combine(job.labels|d({}))|to_json }}
{% endif %}
{% if job.target_files|d(False) %}
file_sd_configs:
- files:
{% for path in job.target_files %}
- {{ path }}
{% endfor %}
{% endif %}
{% for i in ['scrape_timeout', 'scrape_interval'] if (prometheus_agent|combine(prometheus_agent.agents.snmp)|combine(job))[i] %}
{{ i }}: {{ (prometheus_agent|combine(job))[i] }}
{{ i }}: {{ (prometheus_agent|combine(prometheus_agent.agents.snmp)|combine(job))[i] }}
{% endfor %}
tls_config:
ca_file: /etc/prometheus/targetcerts/{{ inventory_hostname }}.crt
@ -87,6 +108,9 @@
target_label: module
- target_label: __address__
replacement: {{ inventory_hostname }}:{{ prometheus_agent.scrapers[item].snmp }}
{% for relabel_config in job.relabel_configs|d([]) %}
- {{ relabel_config|tojson }}
{% endfor %}
{% endfor %}
{% endif %}