Combine two tags into a new one

Hi!!
I have been using Telegraf for SNMP monitoring switch and routers interfaces on various vendors (Mikrotik, Huawei, Arista and UBNT). I have a problem where I need to combine ifAlias and ifDescr into one tag, for example:

I have:

ifAlias= ether1
ifDescr= uplink_6881

And combine it into:
ifFullName= ether1-uplink_6881

I wonder if this is possible with Telegraf? It will simplify a lot my day to day, as I have the full data of the interface role on a single tag.

Many thanks in advance, Diego

Hey @dmayan-ss,

this is what the template processor is made for. You should be able to combine them via

[[processors.template]]
  ## Go template used to create the tag name of the output. In order to
  ## ease TOML escaping requirements, you should use single quotes around
  ## the template string.
  tag = "ifFullName"

  ## Go template used to create the tag value of the output. In order to
  ## ease TOML escaping requirements, you should use single quotes around
  ## the template string.
  template = '{{ .Tag "ifAlias" }}-{{ .Tag "ifDescr" }}'

This is amazing, thanks!

Can this transformation be applied only if ifAlias is not empty?

Thanks again!

In this case you might want to look into metric filtering to only apply the processor to metrics meeting the condition. In your case it’s probably

[[processors.template]]
  ...  
  [processors.template.tagdrop]
    ifAlias = [""]

Please not that the tagdrop table needs to be placed at the end of the processor due to TOML constraints as otherwise all other settings will be interpreted as tagdrop settings…

Thank you for your awesome help!

1 Like

@srebhan Processors.template applies globally, how can I limit to the current config file ?

@max6491 you are a negromancer! :wink: Take a look at metric filtering!