Input plugin alias as a tag for routing

Hi,

I am configuring the inputs.opcua_listenerplugin in bracketed group notation. When doing so it is not possible to add default tags to the top level (the connection itself). This means I have to repeat all common tags in every single group.

To solve this missing feature I want to use default processors.defaults to set the default tags for a connection. However I need to be able to tagpassthe metric coming from a specific input where the configured default tags apply.

Is there a way to get the aliasof a plugin to be added as a tag? This would be by far the easiest to know where a metric originated from.

One way to work arround this would be to add a name_prefixto the connection and route based on the prefix. But I don’t want this prefix to clutter my measurement names as it is only for use in telegraf. So one would have to remove the prefix somehow.

To do this I first went to the processors.strings.trim_prefixfunction, but this is not dynamic enough as you would have to define each prefix you used. So regex it is…

In my case I used a prefix ending with pipe symbol so the processor looks as follows:

[[processors.regex]]
  alias = "trim name prefix"
  order = 1000000
  log_level = "debug"
  [[processors.regex.metric_rename]]
    pattern = '^(.*?)\|'

Note the order number is verry high, this is the last number I defined before outputs.

But just having the input alias as a tag would simplify this whole ordeal to a simple tagexclude.

Does anybody have better suggestions on how to do this?

I solved my problem for now, but just want to share some thoughts.

Why are you saying that?

What’s wrong with this?

# Retrieve data from OPCUA devices
[[inputs.opcua_listener]]

  endpoint = ""

  [inputs.opcua_listener.tags]
    tag1 = "value1"
    tag2 = "value2"

  [[inputs.opcua_listener.group]]
    name = "group1"
    ## ...

  [[inputs.opcua_listener.group]]
    name = "group2"
    ## ...

And before you’re saying it’s not documented, it surely is.

Hi, thanks for your fast response. Apparently I was blinded by the use of default tags, which are not possible on the connection level (now it’s obvious to me why).

This is great, I am glad I posted this even if it was kind of stupid.

Also learned how to use regex, might come in handy someday.