Merge "Add influxdb input"
diff --git a/metadata/service/agent/input/http_listener.yml b/metadata/service/agent/input/http_listener.yml
new file mode 100644
index 0000000..a5ff0c6
--- /dev/null
+++ b/metadata/service/agent/input/http_listener.yml
@@ -0,0 +1,11 @@
+parameters:
+  telegraf:
+    agent:
+      input:
+        http_listener:
+          bind:
+            address: 127.0.0.1
+            port: 8186
+          read_timeout: 10s
+          write_timeout: 10s
+          tagexclude: ['hostname']
diff --git a/metadata/service/agent/remote.yml b/metadata/service/agent/remote/init.yml
similarity index 100%
rename from metadata/service/agent/remote.yml
rename to metadata/service/agent/remote/init.yml
diff --git a/metadata/service/agent/remote/input/http_listener.yml b/metadata/service/agent/remote/input/http_listener.yml
new file mode 100644
index 0000000..5413c4f
--- /dev/null
+++ b/metadata/service/agent/remote/input/http_listener.yml
@@ -0,0 +1,11 @@
+parameters:
+  telegraf:
+    remote_agent:
+      input:
+        http_listener:
+          bind:
+            address: 0.0.0.0
+            port: 8186
+          read_timeout: 10s
+          write_timeout: 10s
+          tagexclude: ['hostname']
diff --git a/metadata/service/agent/remote/output/prometheus.yml b/metadata/service/agent/remote/output/prometheus.yml
new file mode 100644
index 0000000..2c242f4
--- /dev/null
+++ b/metadata/service/agent/remote/output/prometheus.yml
@@ -0,0 +1,9 @@
+parameters:
+  telegraf:
+    remote_agent:
+      output:
+        prometheus_client:
+          bind:
+            address: 0.0.0.0
+            port: 9126
+          engine: prometheus
diff --git a/telegraf/agent.sls b/telegraf/agent.sls
index 3b677bc..249ab22 100644
--- a/telegraf/agent.sls
+++ b/telegraf/agent.sls
@@ -19,6 +19,15 @@
     - context:
       agent: {{ agent }}
 
+config_d_dir_agent:
+  file.directory:
+    - name: {{agent.dir.config_d}}
+    - makedirs: True
+    - clean: True
+    - mode: 755
+    - require:
+      - pkg: telegraf_packages_agent
+
 {%- for name,values in agent.input.iteritems() %}
 
 {%- if values is not mapping or values.get('enabled', True) %}
@@ -34,6 +43,7 @@
     - template: jinja
     - require:
       - pkg: telegraf_packages_agent
+      - file: config_d_dir_agent
     - watch_in:
       - service: telegraf_service_agent
     - defaults:
@@ -50,14 +60,6 @@
       - pkg: telegraf_packages_agent
 {%- endif %}
 
-{%- else %}
-input_{{name }}_agent:
-  file.absent:
-    - name: {{ agent.dir.config_d }}/input-{{ name }}.conf
-    - require:
-      - pkg: telegraf_packages_agent
-    - watch_in:
-      - service: telegraf_service_agent
 {%- endif %}
 
 {%- endfor %}
@@ -74,6 +76,7 @@
     - template: jinja
     - require:
       - pkg: telegraf_packages_agent
+      - file: config_d_dir_agent
     - watch_in:
       - service: telegraf_service_agent
     - defaults:
diff --git a/telegraf/files/input/http_listener.conf b/telegraf/files/input/http_listener.conf
new file mode 100644
index 0000000..41f106b
--- /dev/null
+++ b/telegraf/files/input/http_listener.conf
@@ -0,0 +1,6 @@
+[[inputs.http_listener]]
+ service_address = "{{ values.get('bind', {}).address|default('127.0.0.1') }}:{{ values.get('bind', {}).port|default('8186') }}"
+ read_timeout = "{{ values.get('read_timeout', '10s') }}"
+ write_timeout = "{{ values.get('write_timeout', '10s') }}"
+
+{%- include 'telegraf/files/input/_tags.conf' %}
diff --git a/telegraf/files/input/memcached.conf b/telegraf/files/input/memcached.conf
new file mode 100644
index 0000000..b4cd5e3
--- /dev/null
+++ b/telegraf/files/input/memcached.conf
@@ -0,0 +1,3 @@
+[[inputs.memcached]]
+  servers = [{%- for server in values.servers|default([]) %}"{{ server.address }}:{{ server.port }}"{%- if not loop.last%}, {% endif %} {%- endfor %}]
+{%- include 'telegraf/files/input/_tags.conf' %}
diff --git a/telegraf/remote_agent.sls b/telegraf/remote_agent.sls
index 5442d53..d79ffb3 100644
--- a/telegraf/remote_agent.sls
+++ b/telegraf/remote_agent.sls
@@ -13,6 +13,7 @@
   file.directory:
     - name: {{remote_agent.dir.config_d}}
     - makedirs: True
+    - clean: True
     - mode: 755
     - require:
       - file: config_dir_remote_agent
@@ -30,7 +31,7 @@
     - context:
       agent: {{ remote_agent }}
 
-{%- set remote_agent_inputs = {'input': {}} %}
+{%- set remote_agent_inputs = {'input': remote_agent.input} %}
 {%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
   {%- set remote_agent_input = node_grains.get('telegraf', {}).get('remote_agent', {}).get('input', {}) %}
   {%- if remote_agent_input %}
@@ -57,12 +58,6 @@
         name: {{ name }}
         values: {{ values }}
 
-{%- else %}
-input_{{name }}_remote_agent:
-  file.absent:
-    - name: {{ remote_agent.dir.config_d }}/input-{{ name }}.conf
-    - require:
-      - file: config_d_dir_remote_agent
 {%- endif %}
 
 {%- endfor %}