formula-prometheus/prometheus/collector.sls
Bartosz Kupidura c9e81f45db Import prometheus.server in collector
Change-Id: I42e17bd63df43d9bfec3a302bfecf5290c69e0a8
2017-04-28 14:34:50 +02:00

43 lines
1.4 KiB
Text

{%- from "prometheus/map.jinja" import server as prometheus_server with context %}
{%- set service_grains = {'prometheus': {'server': {'alert': {}, 'recording': {}, 'target': {}}}} %}
{%- for service_name, service in pillar.items() %}
{%- if service.get('_support', {}).get('prometheus', {}).get('enabled', False) %}
{%- set grains_fragment_file = service_name+'/meta/prometheus.yml' %}
{%- macro load_grains_file() %}{% include grains_fragment_file ignore missing %}{% endmacro %}
{%- set grains_yaml = load_grains_file()|load_yaml %}
{%- if grains_yaml is mapping %}
{%- set service_grains = salt['grains.filter_by']({'default': service_grains}, merge={'prometheus': grains_yaml}) %}
{%- endif %}
{%- endif %}
{%- endfor %}
prometheus_grains_dir:
file.directory:
- name: /etc/salt/grains.d
- mode: 700
- makedirs: true
- user: root
prometheus_grain:
file.managed:
- name: /etc/salt/grains.d/prometheus
- source: salt://prometheus/files/prometheus.grain
- template: jinja
- mode: 600
- defaults:
service_grains: {{ service_grains|yaml }}
- require:
- file: prometheus_grains_dir
prometheus_grains_file:
cmd.wait:
- name: cat /etc/salt/grains.d/* > /etc/salt/grains
- watch:
- file: prometheus_grain
prometheus_grains_publish:
module.run:
- name: mine.update
- watch:
- cmd: prometheus_grains_file