Merge pull request #7 from tcpcloud/remote_support
Remote check support
diff --git a/collectd/client.sls b/collectd/client.sls
index a5b2128..5937f04 100644
--- a/collectd/client.sls
+++ b/collectd/client.sls
@@ -71,6 +71,22 @@
{%- endif %}
{%- endfor %}
+{%- set remote_plugin = {} %}
+
+{%- if client.remote_collector %}
+
+{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
+
+{%- if node_grains.collectd is defined %}
+
+{%- set remote_plugin = salt['grains.filter_by']({'default': remote_plugin}, merge=node_grains.collectd.get('remote_plugin', {})) %}
+
+{%- endif %}
+
+{%- endfor %}
+
+{%- endif %}
+
collectd_client_grain:
file.managed:
- name: /etc/salt/grains.d/collectd
@@ -94,7 +110,7 @@
{%- for plugin_name, plugin in service_grains.collectd.local_plugin.iteritems() %}
-{%- if (plugin.get('execution', 'local') == 'local' or client.remote_collector) and plugin.get('plugin', 'native') not in ['python'] %}
+{%- if plugin.get('plugin', 'native') not in ['python'] %}
{{ client.config_dir }}/{{ plugin_name }}.conf:
file.managed:
@@ -119,6 +135,37 @@
{%- endfor %}
+{%- if client.remote_collector %}
+
+{%- for plugin_name, plugin in remote_plugin.iteritems() %}
+
+{%- if plugin.get('plugin', 'native') not in ['python'] %}
+
+{{ client.config_dir }}/{{ plugin_name }}.conf:
+ file.managed:
+ {%- if plugin.template is defined %}
+ - source: salt://{{ plugin.template }}
+ - template: jinja
+ - defaults:
+ plugin: {{ plugin|yaml }}
+ {%- else %}
+ - contents: "<LoadPlugin {{ plugin.plugin }}>\n Globals false\n</LoadPlugin>\n"
+ {%- endif %}
+ - user: root
+ - mode: 660
+ - require:
+ - file: collectd_client_conf_dir
+ - require_in:
+ - file: collectd_client_conf_dir_clean
+ - watch_in:
+ - service: collectd_service
+
+{%- endif %}
+
+{%- endfor %}
+
+{%- endif %}
+
{%- if client.file_logging %}
/etc/collectd/conf.d/00_collectd_logfile.conf:
@@ -144,7 +191,8 @@
- group: root
- mode: 660
- defaults:
- plugin: {{ service_grains.collectd.local_plugin|yaml }}
+ local_plugin: {{ service_grains.collectd.local_plugin|yaml }}
+ remote_plugin: {{ remote_plugin|yaml }}
- watch_in:
- service: collectd_service
- require:
@@ -189,6 +237,7 @@
- mode: 640
- defaults:
service_grains: {{ service_grains|yaml }}
+ remote_plugin: {{ remote_plugin|yaml }}
- require:
- file: collectd_client_conf_dir
- require_in:
diff --git a/collectd/files/collectd.conf b/collectd/files/collectd.conf
index fc48a19..8c28563 100644
--- a/collectd/files/collectd.conf
+++ b/collectd/files/collectd.conf
@@ -882,10 +882,16 @@
Include "/etc/collectd/conf.d/00_collectd_logfile.conf"
{%- endif %}
{%- for plugin_name, plugin in service_grains.collectd.local_plugin.iteritems() %}
-{%- if (plugin.get('execution', 'local') == 'local' or client.remote_collector) and plugin.get('plugin', 'native') not in ['python'] %}
+{%- if plugin.get('plugin', 'native') not in ['python'] %}
Include "{{ client.config_dir }}/{{ plugin_name }}.conf"
{%- endif %}
{%- endfor %}
+{%- if client.remote_collector %}
+{%- for plugin_name, plugin in remote_plugin.iteritems() %}
+{%- if plugin.get('plugin', 'native') not in ['python'] %}
+{%- endif %}
+{%- endfor %}
+{%- endif %}
Include "{{ client.config_dir }}/collectd_python.conf"
{%- for backend_name, backend in client.backend.iteritems() %}
Include "{{ client.config_dir }}/collectd_writer_{{ backend_name }}.conf"
diff --git a/collectd/files/collectd_python.conf b/collectd/files/collectd_python.conf
index 6142345..7a279e7 100644
--- a/collectd/files/collectd_python.conf
+++ b/collectd/files/collectd_python.conf
@@ -1,3 +1,4 @@
+{%- from "collectd/map.jinja" import client with context -%}
<LoadPlugin python>
Globals false
</LoadPlugin>
@@ -7,10 +8,18 @@
LogTraces false
Interactive false
- {%- for plugin_name, plugin in plugin.iteritems() %}
- {%- if (plugin.get('execution', 'local') == 'local' or client.remote_collector) and plugin.get('plugin', 'native') == 'python' %}
+ {%- for plugin_name, plugin in local_plugin.iteritems() %}
+ {%- if plugin.get('plugin', 'native') == 'python' %}
{%- include plugin.template %}
{%- endif %}
{%- endfor %}
+ {%- if client.remote_collector %}
+ {%- for plugin_name, plugin in remote_plugin.iteritems() %}
+ {%- if plugin.get('plugin', 'native') == 'python' %}
+ {%- include plugin.template %}
+ {%- endif %}
+ {%- endfor %}
+ {%- endif %}
+
</Plugin>