-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
bugunexpected problem or unintended behaviorunexpected problem or unintended behavior
Milestone
Description
Relevant telegraf.conf:
[[processors.regex]]
namepass = ["RandomData"]
[[processors.regex.tags]]
key = "ComputerName"
pattern = "^(.*?)a$"
replacement = "${1}"
result_key = "ServerName"
[[processors.regex.tags]]
key = "ComputerName"
pattern = "^(.*?)b$"
replacement = "${1}"
result_key = "ServerName"
System info:
Telegraf Version: 1.8.0
OS: Windows Server 2012
Steps to reproduce:
- Use any input plugin. Try to strip off the last character
Expected behavior:
In the above configuration, I would expect that ServerName should be a tag that holds the value of the tag "ComputerName" without the trailing a or b.
Actual behavior:
Only the the configuration of the last regex is honored. I believe what is happening is that when a subsequent regex match fails, it returns an empty string, which then get's reassigned to the tag, overwriting the value that I was interested in.
Additional info:
I believe this could be a quick fix to the regex processor plugin. The fix I made is below, and seems to be working:
for _, converter := range r.Tags {
if value, ok := metric.GetTag(converter.Key); ok {
k, v := r.convert(converter, value)
if k != "" && v != "" {
metric.AddTag(k, v)
}
}
}
for _, converter := range r.Fields {
if value, ok := metric.GetField(converter.Key); ok {
switch value := value.(type) {
case string:
k, v := r.convert(converter, value)
if k != "" && v != "" {
metric.AddField(r.convert(converter, value))
}
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugunexpected problem or unintended behaviorunexpected problem or unintended behavior