Merge "Allow to override the datasource name"
diff --git a/grafana/collector.sls b/grafana/collector.sls
index 0457974..e5d665e 100644
--- a/grafana/collector.sls
+++ b/grafana/collector.sls
@@ -1,52 +1,11 @@
{%- from "grafana/map.jinja" import collector with context %}
{%- if collector.get('enabled', False) %}
-grafana_grains_dir:
- file.directory:
- - name: /etc/salt/grains.d
- - mode: 700
- - makedirs: true
- - user: root
+# This state is only used to map grains.collector pillar. Grains are now
+# managed from salt.minion.grains so we will just include it in case it's
+# executed explicitly
-{%- set service_grains = {} %}
-
-{# Loading the other service support metadata for localhost #}
-
-{%- for service_name, service in pillar.iteritems() %}
-{%- if service.get('_support', {}).get('grafana', {}).get('enabled', False) %}
-
-{%- macro load_grains_file(grains_fragment_file) %}{% include grains_fragment_file ignore missing %}{% endmacro %}
-
-{%- set grains_fragment_file = service_name+'/meta/grafana.yml' %}
-{%- set grains_yaml = load_grains_file(grains_fragment_file)|load_yaml %}
-{%- set service_grains = salt['grains.filter_by']({'default': service_grains}, merge=grains_yaml) %}
-
-{%- endif %}
-{%- endfor %}
-
-grafana_grain:
- file.managed:
- - name: /etc/salt/grains.d/grafana
- - source: salt://grafana/files/grafana.grain
- - template: jinja
- - user: root
- - mode: 600
- - defaults:
- service_grains:
- grafana: {{ service_grains|yaml }}
- - require:
- - file: grafana_grains_dir
-
-grafana_grains_file:
- cmd.wait:
- - name: cat /etc/salt/grains.d/* > /etc/salt/grains
- - watch:
- - file: grafana_grain
-
-grafana_grains_publish:
- module.run:
- - name: mine.update
- - watch:
- - cmd: grafana_grains_file
+include:
+ - salt.minion.grains
{%- endif %}
diff --git a/grafana/files/grafana.grain b/grafana/files/grafana.grain
deleted file mode 100644
index 3e3b373..0000000
--- a/grafana/files/grafana.grain
+++ /dev/null
@@ -1 +0,0 @@
-{{ service_grains|yaml(False) }}
diff --git a/grafana/init.sls b/grafana/init.sls
index 9829b7f..9562a07 100644
--- a/grafana/init.sls
+++ b/grafana/init.sls
@@ -7,7 +7,4 @@
{%- if pillar.grafana.client is defined %}
- grafana.client
{%- endif %}
-{%- if pillar.grafana.collector is defined %}
-- grafana.collector
-{%- endif %}
{%- endif %}
diff --git a/grafana/map.jinja b/grafana/map.jinja
index 2b38de3..dc0a52d 100644
--- a/grafana/map.jinja
+++ b/grafana/map.jinja
@@ -54,11 +54,3 @@
{%- endload %}
{%- set client = salt['grains.filter_by'](client_defaults, merge=salt['pillar.get']('grafana:client')) %}
-
-{%- load_yaml as collector_defaults %}
-default:
- storage:
- engine: salt-mine
-{%- endload %}
-
-{%- set collector = salt['grains.filter_by'](collector_defaults, merge=salt['pillar.get']('grafana:collector')) %}
diff --git a/grafana/meta/salt.yml b/grafana/meta/salt.yml
new file mode 100644
index 0000000..7731ec4
--- /dev/null
+++ b/grafana/meta/salt.yml
@@ -0,0 +1,16 @@
+grain:
+ {%- if pillar.grafana.collector is defined %}
+ {%- if collector.get('enabled', False) %}
+ {%- set service_grains = {} %}
+ {%- for service_name, service in pillar.iteritems() %}
+ {%- if service.get('_support', {}).get('grafana', {}).get('enabled', False) %}
+ {%- macro load_grains_file(grains_fragment_file) %}{% include grains_fragment_file ignore missing %}{% endmacro %}
+ {%- set grains_fragment_file = service_name+'/meta/grafana.yml' %}
+ {%- set grains_yaml = load_grains_file(grains_fragment_file)|load_yaml %}
+ {%- set service_grains = salt['grains.filter_by']({'default': service_grains}, merge=grains_yaml) %}
+ {%- endif %}
+ {%- endfor %}
+ grafana:
+ {{ service_grains|yaml(False)|indent(4) }}
+ {%- endif %}
+ {%- endif %}