Move grain from sls to file
Change-Id: Ie5c7e834c52665f8cbc7aba7f18b8865874d6e43
diff --git a/telegraf/agent.sls b/telegraf/agent.sls
index f272fd3..1ad3382 100644
--- a/telegraf/agent.sls
+++ b/telegraf/agent.sls
@@ -54,26 +54,24 @@
name: {{ name }}
values: {{ values }}
-{%- if name == 'prometheus_client' %}
-
-{%- if values.bind.address == '0.0.0.0' %}
-{%- set address = grains['fqdn_ip4'][0] %}
-{%- else %}
-{%- set address = values.bind.address %}
-{%- endif %}
-
-prometheus_client_grain:
- grains.present:
- - name: prometheus_client
- - force: True
- - value:
- address: {{ address }}
- port: {{ values.bind.port }}
-
-{%- 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
+ - 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
new file mode 100644
index 0000000..9a635d2
--- /dev/null
+++ b/telegraf/files/input/procstat.conf
@@ -0,0 +1,15 @@
+{%- for item in values %}
+[[inputs.{{ name }}]]
+{%- if item.pid_file is defined %}
+ pid_file = "{{ item.pid_file }}"
+{%- endif %}
+{%- if item.exe is defined %}
+ exe = "{{ item.exe }}"
+{%- endif %}
+{%- if item.user is defined %}
+ user = "{{ item.user }}"
+{%- endif %}
+{%- if item.process_name is defined %}
+ process_name = "{{ item.process_name }}"
+{%- endif %}
+{%- endfor %}
diff --git a/telegraf/files/telegraf.grain b/telegraf/files/telegraf.grain
new file mode 100644
index 0000000..71ac710
--- /dev/null
+++ b/telegraf/files/telegraf.grain
@@ -0,0 +1,15 @@
+{%- from "telegraf/map.jinja" import agent with context -%}
+{%- if agent.output is defined %}
+ {%- if agent.output.prometheus_client is defined %}
+ {%- if agent.output.prometheus_client.bind.address == '0.0.0.0' %}
+ {%- set address = grains['fqdn_ip4'][0] %}
+ {%- 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': {}} -%}
+ {%- endif %}
+{%- endif %}
+
+{{ service_grains|yaml(False) }}