Merge grains with pillars for static targets
Change-Id: I2f85fe2f9cc67d2d03d5e8dad5ac0b74e82b0fcc
This commit is contained in:
parent
220497bb8e
commit
9a986bebf7
2 changed files with 13 additions and 7 deletions
|
@ -37,24 +37,26 @@ remote_write:
|
|||
rule_files:
|
||||
- alerts.yml
|
||||
|
||||
{%- set static_target = {} %}
|
||||
{%- set static_target = server.target.static %}
|
||||
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
||||
{%- set static_grain = node_grains.get('prometheus', {}).get('server', {}).get('target', {}).get('static', {}) %}
|
||||
{%- for job_name, job in static_grain.iteritems() %}
|
||||
{%- if static_target[job_name] is not defined %}
|
||||
{%- do static_target.update({job_name: []}) %}
|
||||
{%- do static_target.update({job_name: {}}) %}
|
||||
{%- endif %}
|
||||
{%- for target in job.get('endpoint') %}
|
||||
{%- do static_target[job_name].append(target) %}
|
||||
{%- if static_target[job_name]['endpoint'] is not defined %}
|
||||
{%- do static_target[job_name].update({'endpoint': []}) %}
|
||||
{%- endif %}
|
||||
{%- for target in job.get('endpoint', []) %}
|
||||
{%- do static_target[job_name]['endpoint'].append(target) %}
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
|
||||
scrape_configs:
|
||||
{%- for job_name, targets in static_target.iteritems() %}
|
||||
{%- set job = server.get('target', {}).get('static', {}).get(job_name, {}) %}
|
||||
{%- for job_name, job in static_target.iteritems() %}
|
||||
{%- set nodes = [] %}
|
||||
{%- for target in targets + job.get('endpoint', []) %}
|
||||
{%- for target in job.get('endpoint', []) %}
|
||||
{%- set address = "'%s:%d'" | format(target.address, target.port) %}
|
||||
{%- do nodes.append(address) %}
|
||||
{%- endfor %}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
{% set server = salt['grains.filter_by']({
|
||||
'default': {
|
||||
'target': {
|
||||
'static': {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, merge=salt['pillar.get']('prometheus:server')) %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue