Fix grains generation
diff --git a/collectd/client.sls b/collectd/client.sls
index dcd0eb1..856732d 100644
--- a/collectd/client.sls
+++ b/collectd/client.sls
@@ -39,14 +39,14 @@
   - require:
     - pkg: collectd_client_packages
 
-collectd_client_plugins_grains_dir:
+collectd_client_grains_dir:
   file.directory:
   - name: /etc/salt/grains.d
   - mode: 700
   - makedirs: true
   - user: root
 
-collectd_client_plugins_grain:
+collectd_client_grain:
   file.managed:
   - name: /etc/salt/grains.d/collectd
   - source: salt://collectd/files/collectd.grain
@@ -55,12 +55,17 @@
   - mode: 600
   - require:
     - pkg: collectd_client_packages
-    - file: collectd_client_plugins_grains_dir
+    - file: collectd_client_grains_dir
 
-{%- set collectd_plugin_yaml = salt['cmd.run']('[ -e /etc/salt/grains.d/collectd_plugins ] && cat /etc/salt/grains.d/collectd_plugins || echo "collectd_plugin: {}"') %}
-{%- load_yaml as collectd_plugin %}
-{{ collectd_plugin_yaml }}
-{%- endload %}
+collectd_client_grain_validity_check:
+  pkg.installed:
+  - name: python-yaml 
+  cmd.wait:
+  - name: python -c "import yaml; stream = file('/etc/salt/grains.d/sphinx', 'r'); yaml.load(stream); stream.close()"
+  - require:
+    - pkg: collectd_client_grain
+  - watch:
+    - file: collectd_client_grain
 
 {%- for plugin_name, plugin in collectd_plugin.collectd_plugin.iteritems() %}
 
diff --git a/collectd/files/collectd.grain b/collectd/files/collectd.grain
index 38f30a0..6525caf 100644
--- a/collectd/files/collectd.grain
+++ b/collectd/files/collectd.grain
@@ -1,9 +1,10 @@
-collectd_plugins:
-
+{%- set grains = {'collectd': {'plugin': {}}} %}
 {%- for service_name, service in pillar.items() %}
 {%- if service.get('_support', {}).get('collectd', {}).get('enabled', False) %}
 {%- set grains_fragment_file = service_name+'/meta/collectd.yml' %}
-{% macro indent_grains_dict() %}{% include grains_fragment_file %}{% endmacro %}
-{{- indent_grains_dict()|indent(2, true) }}
+{%- macro load_grains_file() %}{% include grains_fragment_file %}{% endmacro %}
+{%- set grains_yaml = load_grains_file()|load_yaml %}
+{%- set _dummy = grains.collectd.plugin.update(grains_yaml.check) %}
 {%- endif %}
 {%- endfor %}
+{{ grains|yaml(False) }}
diff --git a/collectd/init.sls b/collectd/init.sls
index 21ec9f4..5519f6a 100644
--- a/collectd/init.sls
+++ b/collectd/init.sls
@@ -1,5 +1,7 @@
 
+{%- if pillar.collectd is defined %}
 include:
-{% if pillar.collectd.client is defined %}
+{%- if pillar.collectd.client is defined %}
 - collectd.client
-{% endif %}
+{%- endif %}
+{%- endif %}
diff --git a/collectd/meta/collectd.yml b/collectd/meta/collectd.yml
index 11323e4..9079e04 100644
--- a/collectd/meta/collectd.yml
+++ b/collectd/meta/collectd.yml
@@ -1,20 +1,21 @@
 {%- if pillar.get('external', {}).network_device is defined %}
-collectd_network_device:
-  plugin: snmp
-  data:
-    std_traffic:
-      type: if_octets
-      table: true
-      instance: 1.3.6.1.2.1.31.1.1.1.1
-      values:
-      - 1.3.6.1.2.1.31.1.1.1.6
-      - 1.3.6.1.2.1.31.1.1.1.10
-    std_rate:
-      type: if_packets
-      table: true
-      instance: 1.3.6.1.2.1.31.1.1.1.1
-      values:
-      - 1.3.6.1.2.1.31.1.1.1.7
-      - 1.3.6.1.2.1.31.1.1.1.11
-  host: {{ pillar.external.network_device }}
+plugin:
+  collectd_network_device:
+    plugin: snmp
+    data:
+      std_traffic:
+        type: if_octets
+        table: true
+        instance: 1.3.6.1.2.1.31.1.1.1.1
+        values:
+        - 1.3.6.1.2.1.31.1.1.1.6
+        - 1.3.6.1.2.1.31.1.1.1.10
+      std_rate:
+        type: if_packets
+        table: true
+        instance: 1.3.6.1.2.1.31.1.1.1.1
+        values:
+        - 1.3.6.1.2.1.31.1.1.1.7
+        - 1.3.6.1.2.1.31.1.1.1.11
+    host: {{ pillar.external.network_device }}
 {%- endif %}
\ No newline at end of file
diff --git a/collectd/meta/sensu.yml b/collectd/meta/sensu.yml
index 76d4c52..9445ffd 100644
--- a/collectd/meta/sensu.yml
+++ b/collectd/meta/sensu.yml
@@ -1,6 +1,7 @@
-local_collectd_proc:
-  command: "PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_procs -C collectd -u root -c 1:1"
-  interval: 60
-  occurrences: 1
-  subscribers:
-  - local-collectd-client
+check:
+  local_collectd_proc:
+    command: "PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_procs -C collectd -u root -c 1:1"
+    interval: 60
+    occurrences: 1
+    subscribers:
+    - local-collectd-client