How to use processors.regex.fields

Hi,

I have fields that come in like this:

Ethernet54/goVendorInfo/vendorSn
Ethernet6/goVendorInfo/vendorDateCode
Ethernet6/goVendorInfo/vendorName
Ethernet6/goVendorInfo/vendorPn
Ethernet6/goVendorInfo/vendorRev
Ethernet6/goVendorInfo/vendorSn
Ethernet7/goVendorInfo/vendorDateCode
Ethernet7/goVendorInfo/vendorName

My goal is to try to remove “goVendorInfo” from the field name and have the fieldnames renamed to:

Ethernet54-vendorSn
Ethernet6-vendorDateCode
Ethernet6-vendorName
Ethernet6-vendorPn
Ethernet6-vendorRev
Ethernet6-vendorSn
Ethernet7-vendorDateCode
Ethernet7-vendorName

My input plugin looks like this:

[[inputs.gnmi]]
  addresses = ["router1.mgt.net:50051"]
  username = "$routerUser"
  password = "$routerPass"
  encoding = "proto"
  redial = "10s"
  enable_tls = true
  tls_ca = "/etc/telegraf/router_ca.pem"
  insecure_skip_verify = false
  fieldpass = ["Ethernet*/goVendorInfo*", "Ethernet*/lastDomUpdateTime/rxPower", "Ethernet*/lastDomUpdateTime/txPower", "Ethernet*/domRegisterData/lane1TxPower", "Ethernet*/domRegisterData/lane3OpticalRxPower", "Ethernet*/domRegisterData/lane4TxPower", "Ethernet*/domRegisterData/lane2OpticalRxPower", "Ethernet*/domRegisterData/lane2TxPower", "Ethernet*/domRegisterData/lane1OpticalRxPower", "Ethernet*/domRegisterData/lane3TxPower", "Ethernet*/domRegisterData/lane4OpticalRxPower"]
  [[inputs.gnmi.subscription]]
    name = "na_optics"
    path="/Sysdb/hardware/archer/xcvr/status/all"
    subscription_mode = "sample"
    origin="eos_native"
    sample_interval = "10s"
    suppress_redundant = false

I’m testing with [[processors.regex.fields]] and just trying to capture the first string before the first forward slash and store it to a new field called testing, but I’m not having any luck. If I can figure out how to do this then I think I should be able to extract out the first and third strings to form the new field name.

This is what I have:

[[processors.regex]]
namepass = ["na_optics"]
  [[processors.regex.fields]]
  key = "Ethernet54/domRegisterData/lane4TxPower"
  pattern = "^(\\w+).*"
  replacement = "${1}"
  result_key = "testing"

Also, can wildcards be used in the key definition? Can I use a key that looks like this key = "Ethernet*/domRegisterData/lane4TxPower" to target all keys that begin with “Ethernet”.

Thank you,
Mo

Ok so I think I was making the wrong call to rename the field.
I believe I need to be using [[processors.regex.field_rename]],

[[processors.regex]]
namepass = ["na_optics"]
  [[processors.regex.field_rename]]
  pattern = "^Ethernet(.*)"
  replacement = "${1}"     # Trying to capture everything after Ethernet.

however, when I use this I get an error:

2022-02-04T15:42:56Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf/telegraf.conf: plugin processors.regex: line 94: configuration specified the fields ["tag_rename"], but they weren't used

Line 94 is where I specify [[processors.rename]] since I’m using this plugin to rename a few other fields.

Is it possible to use [[processors.rename]] and [[processors.regex.field_rename]] in the same Telegraf conf file?

I disabled the [[processors.rename]] plugin and still getting the same error.

I think I figured it out. I needed to upgrade my Telegraf version to 1.21.3. I was running 1.19.

2 Likes