Merge "Drop Travis CI support"
diff --git a/LICENSE b/LICENSE
index 3b118ea..aa58d6c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-  Copyright (c) 2017 Mirantis et al.
+  Copyright (c) 2017-2019 Mirantis Inc. et al.
 
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -11,4 +11,3 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-
diff --git a/README.rst b/README.rst
index f639b97..a4e398a 100644
--- a/README.rst
+++ b/README.rst
@@ -39,36 +39,3 @@
           database: test-telegraf
           write_consistency: any
           timeout: 10s
-
-Documentation and Bugs
-======================
-
-To learn how to install and update salt-formulas, consult the documentation
-available online at:
-
-    http://salt-formulas.readthedocs.io/
-
-In the unfortunate event that bugs are discovered, they should be reported to
-the appropriate issue tracker. Use Github issue tracker for specific salt
-formula:
-
-    https://github.com/salt-formulas/salt-formula-logrotate/issues
-
-For feature requests, bug reports or blueprints affecting entire ecosystem,
-use Launchpad salt-formulas project:
-
-    https://launchpad.net/salt-formulas
-
-You can also join salt-formulas-users team and subscribe to mailing list:
-
-    https://launchpad.net/~salt-formulas-users
-
-Developers wishing to work on the salt-formulas projects should always base
-their work on master branch and submit pull request against specific formula.
-
-    https://github.com/salt-formulas/salt-formula-logrotate
-
-Any questions or feedback is always welcome so feel free to join our IRC
-channel:
-
-    #salt-formulas @ irc.freenode.net
diff --git a/debian/control b/debian/control
index a95454d..083561f 100644
--- a/debian/control
+++ b/debian/control
@@ -1,12 +1,12 @@
 Source: salt-formula-telegraf
-Maintainer: Salt Formulas Community <salt-formulas@freelists.org>
+Maintainer: Mirantis Dev <dev@mirantis.com>
 Section: admin
 Priority: optional
 Build-Depends: salt-master, python, python-yaml, debhelper (>= 9)
 Standards-Version: 3.9.6
-Homepage: https://github.com/salt-formulas/salt-formulas
-Vcs-Browser: https://github.com/salt-formulas/salt-formula-telegraf
-Vcs-Git: https://github.com/salt-formulas/salt-formula-telegraf.git
+Homepage: https://www.mirantis.com
+Vcs-Browser: https://gerrit.mcp.mirantis.com/#/admin/projects/salt-formulas/telegraf
+Vcs-Git: https://gerrit.mcp.mirantis.com/salt-formulas/telegraf.git
 
 Package: salt-formula-telegraf
 Architecture: all
diff --git a/debian/copyright b/debian/copyright
index 8e0f18e..9ba62c5 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,12 +1,12 @@
 Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 Upstream-Name: salt-formula-telegraf
-Upstream-Contact: Salt Formulas Community <salt-formulas@freelists.org>
-Source: https://github.com/salt-formulas/salt-formula-telegraf
+Upstream-Contact: Mirantis Dev <dev@mirantis.com>
+Source: https://gerrit.mcp.mirantis.com/salt-formulas/telegraf
 
 Files: *
-Copyright: 2017 Mirantis et al.
+Copyright: 2017-2019 Mirantis Inc. et al
 License: Apache-2.0
-  Copyright (C) 2017 Mirantis et al.
+  Copyright (C) 2017-2019 Mirantis Inc. et al
   .
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
diff --git a/metadata.yml b/metadata.yml
index 1f0a46c..a5b7fc2 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,3 +1,3 @@
 name: "telegraf"
 version: "0.1"
-source: "https://github.com/salt-formulas/salt-formula-telegraf"
+source: "https://gerrit.mcp.mirantis.com/salt-formulas/telegraf"
diff --git a/metadata/service/agent/output/prometheus_client.yml b/metadata/service/agent/output/prometheus_client.yml
index 5537b75..57b98bb 100644
--- a/metadata/service/agent/output/prometheus_client.yml
+++ b/metadata/service/agent/output/prometheus_client.yml
@@ -6,4 +6,5 @@
           bind:
             address: 0.0.0.0
             port: 9126
+          string_as_label: false
           engine: prometheus
diff --git a/metadata/service/agent/remote/output/prometheus.yml b/metadata/service/agent/remote/output/prometheus.yml
index 2c242f4..0feb428 100644
--- a/metadata/service/agent/remote/output/prometheus.yml
+++ b/metadata/service/agent/remote/output/prometheus.yml
@@ -6,4 +6,5 @@
           bind:
             address: 0.0.0.0
             port: 9126
+          string_as_label: false
           engine: prometheus
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
index a4b5e81..efd57d9 100644
--- a/metadata/service/support.yml
+++ b/metadata/service/support.yml
@@ -1,5 +1,7 @@
 parameters:
   telegraf:
     _support:
+      fluentd:
+        enabled: true
       prometheus:
         enabled: true
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/input/_tls.conf b/telegraf/files/input/_tls.conf
new file mode 100644
index 0000000..1ffa77c
--- /dev/null
+++ b/telegraf/files/input/_tls.conf
@@ -0,0 +1,12 @@
+{%- if values.tls_ca is defined %}
+  tls_ca = values.tls_ca
+{%- endif %}
+{%- if values.tls_cert is defined %}
+  tls_cert = values.tls_cert
+{%- endif %}
+{%- if values.tls_key is defined %}
+  tls_key = values.tls_key
+{%- endif %}
+{%- if values.insecure_skip_verify is defined %}
+  insecure_skip_verify = values.insecure_skip_verify
+{%- endif %}
diff --git a/telegraf/files/input/http_response.conf b/telegraf/files/input/http_response.conf
index 40e1744..96adaf4 100644
--- a/telegraf/files/input/http_response.conf
+++ b/telegraf/files/input/http_response.conf
@@ -16,6 +16,7 @@
 {%- endif -%}
 
 {%- include 'telegraf/files/input/_common.conf' %}
+{%- include 'telegraf/files/input/_filters.conf' %}
   {%- for endpoint, parameters in values.iteritems() %}
     {%- if parameters.address is defined %}
   [[inputs.http_response.checks]]
@@ -25,4 +26,3 @@
       {%- endfor %}
     {%- endif %}
   {%- endfor %}
-{%- include 'telegraf/files/input/_filters.conf' %}
diff --git a/telegraf/files/input/ipmi_sensor.conf b/telegraf/files/input/ipmi_sensor.conf
new file mode 100644
index 0000000..22a8f70
--- /dev/null
+++ b/telegraf/files/input/ipmi_sensor.conf
@@ -0,0 +1,20 @@
+[[inputs.ipmi_sensor]]
+{%- include 'telegraf/files/input/_common.conf' %}
+
+{%- if values.path is defined %}
+path = "{{ values.path }}"
+{%- endif %}
+{%- if values.privilege is defined %}
+privilege = "{{ values.privilege }}"
+{%- endif %}
+{%- if values.servers is defined %}
+servers = {{ values.servers }}
+{%- endif %}
+{%- if values.timeout is defined %}
+timeout = "{{ values.timeout }}"
+{%- endif %}
+{%- if values.metric_version is defined %}
+metric_version = {{ values.metric_version }}
+{%- endif %}
+
+{%- include 'telegraf/files/input/_filters.conf' %}
diff --git a/telegraf/files/input/snmp.conf b/telegraf/files/input/snmp.conf
new file mode 100644
index 0000000..5b11e7a
--- /dev/null
+++ b/telegraf/files/input/snmp.conf
@@ -0,0 +1,99 @@
+[[inputs.snmp]]
+{%- include 'telegraf/files/input/_common.conf' %}
+
+agents = {{ values.agents }}
+{%- if values.version is defined %}
+version = {{ values.version }}
+{%- endif %}
+{%- if values.name is defined %}
+name = "{{ values.name }}"
+{%- endif %}
+{%- if values.community is defined %}
+community = "{{ values.community }}"
+{%- endif %}
+{%- if values.max_repetitions is defined %}
+max_repetitions = {{ values.max_repetitions }}
+{%- endif %}
+{%- if values.sec_name is defined %}
+sec_name = "{{ values.sec_name }}"
+{%- endif %}
+{%- if values.auth_protocol is defined %}
+auth_protocol = "{{ values.auth_protocol }}"
+{%- endif %}
+{%- if values.auth_password is defined %}
+auth_password = "{{ values.auth_password }}"
+{%- endif %}
+{%- if values.sec_level is defined %}
+sec_level = "{{ values.sec_level }}"
+{%- endif %}
+{%- if values.context_name is defined %}
+context_name = "{{ values.context_name }}"
+{%- endif %}
+{%- if values.priv_protocol is defined %}
+priv_protocol = "{{ values.priv_protocol }}"
+{%- endif %}
+{%- if values.priv_password is defined %}
+priv_password = "{{ values.priv_password }}"
+{%- endif %}
+
+{%- include 'telegraf/files/input/_filters.conf' %}
+
+{%- if values.fields is defined %}
+  {%- for field in values.fields %}
+  [[inputs.snmp.field]]
+  oid = "{{ field.oid }}"
+    {%- if field.name is defined %}
+  name = "{{ field.name }}"
+    {%- endif %}
+    {%- if field.oid_index_suffix is defined %}
+  oid_index_suffix = "{{ field.oid_index_suffix }}"
+    {%- endif %}
+    {%- if field.oid_index_length is defined %}
+  oid_index_length = {{ field.oid_index_length }}
+    {%- endif %}
+    {%- if field.is_tag is defined %}
+  is_tag = {{ field.is_tag }}
+    {%- endif %}
+    {%- if field.conversion is defined %}
+  conversion = "{{ field.conversion }}"
+    {%- endif %}
+  {%- endfor %}
+{%- endif %}
+
+{%- if values.tables is defined %}
+  {%- for table in values.tables %}
+  [[inputs.snmp.table]]
+    {%- if table.name is defined %}
+  name = "{{ table.name }}"
+    {%- endif %}
+    {%- if table.oid is defined %}
+  oid = "{{ table.oid }}"
+    {%- endif %}
+    {%- if table.inherit_tags is defined %}
+  inherit_tags = "{{ table.inherit_tags }}"
+    {%- endif %}
+    {%- if table.index_as_tag is defined %}
+  index_as_tag = {{ table.index_as_tag }}
+    {%- endif %}
+    {%- for field in table.fields %}
+    [[inputs.snmp.table.field]]
+    oid = "{{ field.oid }}"
+      {%- if field.name is defined %}
+    name = "{{ field.name }}"
+      {%- endif %}
+      {%- if field.oid_index_suffix is defined %}
+    oid_index_suffix = "{{ field.oid_index_suffix }}"
+      {%- endif %}
+      {%- if field.oid_index_length is defined %}
+    oid_index_length = {{ field.oid_index_length }}
+      {%- endif %}
+      {%- if field.is_tag is defined %}
+    is_tag = {{ field.is_tag }}
+      {%- endif %}
+      {%- if field.conversion is defined %}
+    conversion = "{{ field.conversion }}"
+      {%- endif %}
+    {%- endfor %}
+  {%- endfor %}
+{%- endif %}
+
diff --git a/telegraf/files/input/x509.conf b/telegraf/files/input/x509.conf
new file mode 100644
index 0000000..aa82a8f
--- /dev/null
+++ b/telegraf/files/input/x509.conf
@@ -0,0 +1,10 @@
+[[inputs.x509_cert]]
+{%- include 'telegraf/files/input/_common.conf' %}
+{%- if values.sources is defined %}
+  sources = {{ values.sources }}
+{%- endif %}
+{%- if values.timeout is defined %}
+  timeout = "{{ values.timeout }}"
+{%- endif %}
+{%- include 'telegraf/files/input/_tls.conf' %}
+{%- include 'telegraf/files/input/_filters.conf' %}
diff --git a/telegraf/files/output/prometheus_client.conf b/telegraf/files/output/prometheus_client.conf
index eb7d7fc..bbac5f2 100644
--- a/telegraf/files/output/prometheus_client.conf
+++ b/telegraf/files/output/prometheus_client.conf
@@ -1,8 +1,11 @@
 [[outputs.prometheus_client]]
 {%- if values is defined %}
 listen = "{{ values.bind.address }}:{{ values.bind.port }}"
-{%- if values.expiration_interval is defined %}
+  {%- if values.expiration_interval is defined %}
 expiration_interval = "{{ values.expiration_interval }}"
-{%- endif %}
+  {%- endif %}
+  {%- if values.string_as_label is defined %}
+string_as_label = {{ values.string_as_label|lower }}
+  {%- endif %}
 {%- endif %}
 {%- include 'telegraf/files/input/_filters.conf' %}
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/meta/fluentd.yml b/telegraf/meta/fluentd.yml
new file mode 100644
index 0000000..726e835
--- /dev/null
+++ b/telegraf/meta/fluentd.yml
@@ -0,0 +1,34 @@
+{%- if pillar.get('fluentd', {}).get('agent', {}).get('enabled', False) %}
+{%- set positiondb = pillar.fluentd.agent.dir.positiondb %}
+{%- if grains.get('init') == 'systemd' %}
+agent:
+  plugin:
+    fluent-plugin-systemd:
+      deb: ['td-agent-additional-plugins']
+  config:
+    label:
+      telegraf:
+        filter:
+          add_severity_label:
+            tag: '**'
+            type: record_transformer
+            enable_ruby: true
+            record:
+              - name: severity_label
+                value: '${ if record["Payload"].include? "E!"; "ERROR"; elsif record["Payload"].include? "W!"; "WARNING"; elsif record["Payload"].include? "D!"; "DEBUG"; else; record["severity_label"]; end }'
+          add_severity:
+            require:
+              - add_severity_label
+            tag: '**'
+            type: record_transformer
+            enable_ruby: true
+            record:
+              - name: Severity
+                value: '${ { 8=>"TRACE",7=>"DEBUG",6=>"INFO",5=>"NOTICE",4=>"WARNING",3=>"ERROR",2=>"CRITICAL",1=>"ALERT",0=>"EMERGENCY" }.key(record["severity_label"]) }'
+        match:
+          push_to_default:
+            tag: '**'
+            type: relabel
+            label: default_output
+{%- endif %}
+{%- endif %}
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: