Move input definitions to support.yml

Change-Id: I37f31112777ff0292fc3da257faaf72ff90638f1
diff --git a/README.rst b/README.rst
index 30a6f38..120f21b 100644
--- a/README.rst
+++ b/README.rst
@@ -24,10 +24,7 @@
             address: 0.0.0.0
             port: 9126
           engine: prometheus
-      input:
-        diskio:
-        processes:
-        net:
+
 
 Documentation and Bugs
 ======================
diff --git a/telegraf/agent.sls b/telegraf/agent.sls
index 1ad3382..04707ab 100644
--- a/telegraf/agent.sls
+++ b/telegraf/agent.sls
@@ -16,7 +16,38 @@
     - require:
       - pkg: telegraf_packages
 
-{%- for name,values in agent.input.iteritems() %}
+{%- set service_grains = {'telegraf': {'agent': {'input': {}}}} %}
+{%- 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' %}
+    {%- 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={'telegraf': grains_yaml}) %}
+    {%- endif %}
+  {%- endif %}
+{%- endfor %}
+
+telegraf_grains_dir:
+  file.directory:
+  - name: /etc/salt/grains.d
+  - mode: 700
+  - makedirs: true
+  - user: root
+
+telegraf_grain:
+  file.managed:
+  - name: /etc/salt/grains.d/telegraf
+  - source: salt://telegraf/files/telegraf.grain
+  - template: jinja
+  - mode: 600
+  - defaults:
+    service_grains: {{ service_grains|yaml }}
+  - require:
+    - file: telegraf_grains_dir
+
+{%- set telegraf_input = service_grains.telegraf.agent.input %}
+{%- for name,values in telegraf_input.iteritems() %}
 
 input_{{ name }}:
   file.managed:
@@ -56,22 +87,6 @@
 
 {%- endfor %}
 
-telegraf_grains_dir:
-  file.directory:
-  - name: /etc/salt/grains.d
-  - mode: 700
-  - makedirs: true
-  - user: root
-
-telegraf_grain:
-  file.managed:
-  - name: /etc/salt/grains.d/telegraf
-  - source: salt://telegraf/files/telegraf.grain
-  - template: jinja
-  - mode: 600
-  - require:
-    - file: telegraf_grains_dir
-
 telegraf_service:
   service.running:
     - name: telegraf
diff --git a/telegraf/files/input/procstat.conf b/telegraf/files/input/procstat.conf
index 9a635d2..af5aedf 100644
--- a/telegraf/files/input/procstat.conf
+++ b/telegraf/files/input/procstat.conf
@@ -6,6 +6,9 @@
 {%- if item.exe is defined %}
   exe = "{{ item.exe }}"
 {%- endif %}
+{%- if item.pattern is defined %}
+  pattern = "{{ item.pattern }}"
+{%- endif %}
 {%- if item.user is defined %}
   user = "{{ item.user }}"
 {%- endif %}
diff --git a/telegraf/files/telegraf.grain b/telegraf/files/telegraf.grain
index 71ac710..f9625aa 100644
--- a/telegraf/files/telegraf.grain
+++ b/telegraf/files/telegraf.grain
@@ -6,9 +6,7 @@
     {%- else %}
       {%- set address = agent.output.prometheus_client.bind.address %}
     {%- endif %}
-    {%- set service_grains = {'telegraf': {'prometheus_client': {'address': address, 'port': agent.output.prometheus_client.bind.port}}} %}
-  {%- else %}
-    {%- set service_grains = {'telegraf': {}} -%}
+    {%- do service_grains['telegraf'].update({'prometheus_client': {'address': address, 'port': agent.output.prometheus_client.bind.port}}) %}
   {%- endif %}
 {%- endif %}
 
diff --git a/telegraf/map.jinja b/telegraf/map.jinja
index 9dd1bed..a4ee28d 100644
--- a/telegraf/map.jinja
+++ b/telegraf/map.jinja
@@ -1,18 +1,4 @@
 {% set agent = salt['grains.filter_by']({
-    'default': {
-        'input': {
-           'cpu': {
-             'percpu': 'true',
-             'totalcpu': 'true'
-           },
-           'disk': {
-             'ignore_fs': ['tmpfs', 'devtmpfs']
-           },
-           'mem': {},
-           'system': {},
-        },
-    },
-}, merge=salt['grains.filter_by']({
     'Debian': {
       'pkgs': ['telegraf'],
       'file': {
@@ -22,4 +8,4 @@
         'config': '/etc/telegraf/telegraf.d'
       },
     },
-}, merge=salt['pillar.get']('telegraf:agent'))) %}
+}, merge=salt['pillar.get']('telegraf:agent')) %}