Add processors support to telegraf
Change-Id: I0d8a93b4e36ea7d4135eabef4c63392a273dd925
diff --git a/telegraf/agent.sls b/telegraf/agent.sls
index e082e6d..34a28eb 100644
--- a/telegraf/agent.sls
+++ b/telegraf/agent.sls
@@ -106,6 +106,37 @@
{%- endfor %}
+{%- for name,values in agent.processor.iteritems() %}
+
+processor_{{ name }}_agent:
+ file.managed:
+ - name: {{ agent.dir.config_d }}/processor-{{ name }}.conf
+ - source:
+{%- if values.template is defined %}
+ - salt://{{ values.template }}
+{%- endif %}
+ - salt://telegraf/files/processor/{{ name }}.conf
+ - user: root
+ - group: root
+ - mode: 644
+ - template: jinja
+ - require:
+ - pkg: telegraf_packages_agent
+ - file: config_d_dir_agent
+ - require_in:
+ - file: config_d_dir_agent_clean
+ - watch_in:
+ - service: telegraf_service_agent
+ - defaults:
+ name: {{ name }}
+{%- if values is mapping %}
+ values: {{ values }}
+{%- else %}
+ values: {}
+{%- endif %}
+
+{%- endfor %}
+
telegraf_service_agent:
service.running:
- name: telegraf
diff --git a/telegraf/files/processor/_common.conf b/telegraf/files/processor/_common.conf
new file mode 100644
index 0000000..440106a
--- /dev/null
+++ b/telegraf/files/processor/_common.conf
@@ -0,0 +1,3 @@
+{%- if values.order is defined %}
+ order = {{ values.order }}
+{%- endif %}
diff --git a/telegraf/files/processor/enum.conf b/telegraf/files/processor/enum.conf
new file mode 100644
index 0000000..8174793
--- /dev/null
+++ b/telegraf/files/processor/enum.conf
@@ -0,0 +1,24 @@
+[[processors.enum]]
+{%- include 'telegraf/files/processor/_common.conf' %}
+{%- include 'telegraf/files/input/_filters.conf' -%}
+
+{%- if values.mapping is sequence %}
+ {%- for mapping in values.mapping %}
+ {%- if mapping is mapping %}
+ [[processors.enum.mapping]]
+ field = "{{ mapping.field }}"
+ {%- if mapping.dest is defined %}
+ dest = "{{ mapping.dest }}"
+ {%- endif %}
+ {%- if mapping.default is defined %}
+ default = {{ mapping.default }}
+ {%- endif %}
+ {%- if mapping.value_mappings is mapping %}
+ [processors.enum.mapping.value_mappings]
+ {%- for key, value in mapping.value_mappings.iteritems()|sort %}
+ {{ key }} = {{ value }}
+ {%- endfor %}
+ {%- endif %}
+ {%- endif %}
+ {%- endfor %}
+{%- endif %}
diff --git a/telegraf/map.jinja b/telegraf/map.jinja
index 3119a8d..4dc0c85 100644
--- a/telegraf/map.jinja
+++ b/telegraf/map.jinja
@@ -18,7 +18,7 @@
}, merge=salt['pillar.get']('telegraf:remote_agent')) %}
{# Collect configuration from */meta/telegraf.yml #}
-{%- set telegraf_grains = {'telegraf': {'agent': {'input': {}}, 'remote_agent': {'input':{}, 'output':{}}}} %}
+{%- set telegraf_grains = {'telegraf': {'agent': {'input': {}, 'output': {}, 'processor': {}}, 'remote_agent': {'input':{}, 'output':{}, 'processor': {}}}} %}
{%- for service_name, service in pillar.items() %}
{%- if service.get('_support', {}).get('telegraf', {}).get('enabled', False) %}
{%- set grains_fragment_file = service_name+'/meta/telegraf.yml' %}
diff --git a/telegraf/remote_agent.sls b/telegraf/remote_agent.sls
index 4d9a50d..d12ee94 100644
--- a/telegraf/remote_agent.sls
+++ b/telegraf/remote_agent.sls
@@ -133,6 +133,47 @@
{%- endfor %}
+{%- set remote_agent_processors = {} %}
+{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
+ {%- set remote_agent_processor = node_grains.get('telegraf', {}).get('remote_agent', {}).get('processor', {}) %}
+ {%- if remote_agent_processor %}
+ {%- do salt['defaults.merge'](remote_agent_processors, remote_agent_processor) %}
+ {%- endif %}
+{%- endfor %}
+{%- do salt['defaults.merge'](remote_agent_processors, remote_agent.processor) %}
+
+{%- for name,values in remote_agent_processors.iteritems() %}
+
+processor_{{ name }}_remote_agent:
+ file.managed:
+ - name: {{ remote_agent.dir.config_d }}/processor-{{ name }}.conf
+ - source:
+{%- if values.template is defined %}
+ - salt://{{ values.template }}
+{%- endif %}
+ - salt://telegraf/files/processor/{{ name }}.conf
+ - user: root
+ - group: root
+ - mode: 644
+ - template: jinja
+ - onchanges_in:
+{%- for docker_id in docker_ids.split() %}
+ - cmd: {{docker_id}}_remote_agent_reload
+{%- endfor %}
+ - require:
+ - file: config_d_dir_remote_agent
+ - require_in:
+ - file: config_d_dir_remote_agent_clean
+ - defaults:
+ name: {{ name }}
+{%- if values is mapping %}
+ values: {{ values }}
+{%- else %}
+ values: {}
+{%- endif %}
+
+{%- endfor %}
+
{%- for docker_id in docker_ids.split() %}
{{docker_id }}_remote_agent_reload:
cmd.run: