如何解决Telegraf processor.regex 基于两种模式创建一个新标签
我正在使用 Telegraf 的 [[processors.regex]] 创建替换标签。
需要从现有标签“instance”添加一个新标签“custom_instance”。
- 匹配到第一次出现的“#”
- 如果标签没有“#”,那么它应该简单地复制相同的值
Actual output
> Process,host=A700459-W10,custom_instance=chrome,instance=chrome#28,objectname=Process
> Process,instance=CmRcService,objectname=Process
它不会创建 CmRcService 的替代
Expected output
> Process,custom_instance=CmRcService,objectname=Process
有两种模式:这个模式“^(.?)#.$”有效并创建了一个替代,而这个“^[^#]+$”没有,不知道为什么?
[[processors.regex]]
namepass = ["Process"]
# Tag and field conversions defined in a separate sub-tables
[[processors.regex.tags]]
## Tag to change
key = "instance"
## Regular expression to match on a tag value
pattern = "^(.*?)#.*$"
## Matches of the pattern will be replaced with this string. Use ${1}
## notation to use the text of the first submatch.
replacement = "${1}"
result_key = "custom_instance"
[[processors.regex.tags]]
## Tag to change
key = "instance"
## Regular expression to match on a tag value
pattern = "^[^#]+$"
## Matches of the pattern will be replaced with this string. Use ${1}
## notation to use the text of the first submatch.
replacement = "${1}"
result_key = "custom_instance"
是否有其他方法可以根据现有值简单地创建替换标签? if "#" then 匹配到第一次出现 否则只需复制相同的值
解决方法
想通了 第二个模式将替换 = "${0}"
[[processors.regex]]
namepass = ["Process"]
# Tag and field conversions defined in a separate sub-tables
[[processors.regex.tags]]
## Tag to change
key = "instance"
## Regular expression to match on a tag value
pattern = "^(.*?)#.*$"
## Matches of the pattern will be replaced with this string. Use ${1}
## notation to use the text of the first submatch.
replacement = "${1}"
result_key = "custom_instance"
[[processors.regex.tags]]
## Tag to change
key = "instance"
## Regular expression to match on a tag value
pattern = "^[^#]+$"
## Matches of the pattern will be replaced with this string. Use ${1}
## notation to use the text of the first submatch.
replacement = "${0}"
result_key = "custom_instance"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。