Merge grains with pillars for static targets

Change-Id: I2f85fe2f9cc67d2d03d5e8dad5ac0b74e82b0fcc
This commit is contained in:
Bartosz Kupidura 2017-06-26 15:34:08 +02:00 committed by Olivier Bourdon
parent 220497bb8e
commit 9a986bebf7
2 changed files with 13 additions and 7 deletions

View file

@ -37,24 +37,26 @@ remote_write:
rule_files: rule_files:
- alerts.yml - alerts.yml
{%- set static_target = {} %} {%- set static_target = server.target.static %}
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %} {%- 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', {}) %} {%- set static_grain = node_grains.get('prometheus', {}).get('server', {}).get('target', {}).get('static', {}) %}
{%- for job_name, job in static_grain.iteritems() %} {%- for job_name, job in static_grain.iteritems() %}
{%- if static_target[job_name] is not defined %} {%- if static_target[job_name] is not defined %}
{%- do static_target.update({job_name: []}) %} {%- do static_target.update({job_name: {}}) %}
{%- endif %} {%- endif %}
{%- for target in job.get('endpoint') %} {%- if static_target[job_name]['endpoint'] is not defined %}
{%- do static_target[job_name].append(target) %} {%- 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 %} {%- endfor %}
{%- endfor %} {%- endfor %}
scrape_configs: scrape_configs:
{%- for job_name, targets in static_target.iteritems() %} {%- for job_name, job in static_target.iteritems() %}
{%- set job = server.get('target', {}).get('static', {}).get(job_name, {}) %}
{%- set nodes = [] %} {%- set nodes = [] %}
{%- for target in targets + job.get('endpoint', []) %} {%- for target in job.get('endpoint', []) %}
{%- set address = "'%s:%d'" | format(target.address, target.port) %} {%- set address = "'%s:%d'" | format(target.address, target.port) %}
{%- do nodes.append(address) %} {%- do nodes.append(address) %}
{%- endfor %} {%- endfor %}

View file

@ -1,5 +1,9 @@
{% set server = salt['grains.filter_by']({ {% set server = salt['grains.filter_by']({
'default': { 'default': {
'target': {
'static': {
},
},
}, },
}, merge=salt['pillar.get']('prometheus:server')) %} }, merge=salt['pillar.get']('prometheus:server')) %}