dj-wasabi / ansible-telegraf

Installing and configuring Telegraf via Ansible for RedHat/Debian/Ubuntu/Windows/Suse.
MIT License
134 stars 116 forks source link

Revise Templates To allow Different Types Of Filters #91

Open zachdesai opened 5 years ago

zachdesai commented 5 years ago

Is your feature request related to a problem? Please describe. When using inputs.logparser, I'd like to template applying grok filters - this requires a file which looks like ` [[inputs.logparser]]

files = ["/var/log/apache/access.log"]

from_beginning = False

[inputs.logparser.grok]

patterns = ["%{COMBINED_LOG_FORMAT}"]

measurement = "apache_access_log"

` I'm unsure if this is possible already with this role, but I couldn't figure it out.

Describe the solution you'd like Modify the templates to allow custom 'subplugins' (I don't really know the Telegraf nomenclature) - with this, you could also remove the entries for tags, tagpass, tagdrop parts and pass them as subplugins

This seems to be working for me

`{% if item.value.subplugin is defined and item.value.subplugin is iterable %}

{% for subpluginname in item.value.subplugin %}

[inputs.{{ item.value.plugin | default(item.key) }}.{{ subpluginname }}]

{% for items in item.value.subplugin[subpluginname] %}

{{ items }}

{% endfor %}

{% endfor %}

{% endif %} `

Additional context

eg group_vars file logparser: config:

mcaulifn commented 5 years ago

Found this while searching: https://github.com/jtyr/yaml2toml-converter Might be helpful for a completely generic template

dj-wasabi commented 5 years ago

@mcaulifn That looks nice, ever worked with it?

mcaulifn commented 5 years ago

just found it and then tried it out. there seem to be a few kinks but overall a great start.

telegraf_custom_plugins_extra:
  switches:
    inputs.snmp:
      agents:
        - 172.16.1.0
        - 172.16.1.6
        - 172.16.0.30
      version: 2
      community: publiv
      name: system
      field:
        - name: hostname
          oid: .1.3.6.1.2.1.1.5.0
          is_tag: true
        - name: uptime
          oid: .1.3.6.1.2.1.1.3.0
        - name: sysObjectID
          oid: .1.3.6.1.2.1.1.2.0
      table:
        - name: interface_stats
          inherit_tags:
            - hostname
          field:
            - name: ifName
              oid: .1.3.6.1.2.1.31.1.1.1.1
              is_tag: true
      tags:
          deviceType: switch
          customer: me

gets me:

[inputs.snmp]
agents = ['172.16.1.0', '172.16.1.6', '172.16.0.30']
community = "publiv"
name = "system"
version = 2

  [[inputs.snmp.field]]
  is_tag = True
  name = "hostname"
  oid = ".1.3.6.1.2.1.1.5.0"

  [[inputs.snmp.field]]
  name = "uptime"
  oid = ".1.3.6.1.2.1.1.3.0"

  [[inputs.snmp.field]]
  name = "sysObjectID"
  oid = ".1.3.6.1.2.1.1.2.0"

  [[inputs.snmp.table]]
  inherit_tags = ['hostname']
  name = "interface_stats"

    [[field]]
    is_tag = True
    name = "ifName"
    oid = ".1.3.6.1.2.1.31.1.1.1.1"

  [inputs.snmp.tags]
  customer = "me"
  deviceType = "switch"

I can hack around field being incorrect by adding inputs.snmp.table to that level. However, True should be true.

I opened an issue: https://github.com/jtyr/yaml2toml-converter/issues/1

dj-wasabi commented 5 years ago

@mcaulifn Nice!

Do you think you can make a PR that includes the usage of the converter?

mcaulifn commented 5 years ago

I'd like to hear back from the author first to see if he is OK with it.

dj-wasabi commented 5 years ago

@mcaulifn Yeah sure, I agree. 👍

NotDead commented 4 years ago

Is it still open? I have searched for snmp config and as I can see this issue is hanging. The first time I used this role, I thought it was done like @zachdesai suggested and did the wrong config =)

ghost commented 3 years ago

@mcaulifn Could you share to us the modifications that you did in order to get the ability to set the template like you described in https://github.com/dj-wasabi/ansible-telegraf/issues/91#issuecomment-488885685?

mcaulifn commented 3 years ago

@emiliencartesoft There is a link to another PR with the modification I made. I couldn't find anything else locally that I would have changed.

ghost commented 3 years ago

@mcaulifn

@emiliencartesoft There is a link to another PR with the modification I made. I couldn't find anything else locally that I would have changed.

I'm sorry but where is the link of the PR? I can't find it.