【问题标题】:How to copy a value from one field to other if a field exists by using ingestnode pipeline如果使用 ingestnode 管道存在字段,如何将值从一个字段复制到另一个字段
【发布时间】:2021-12-29 13:51:25
【问题描述】:

如果日志中存在名为 prometheus.labels.pod 的字段,我想创建一个名为 kubernetes.pod.name 的新字段。我发现从设置的处理器中我可以将 prometheus.labels.pod 中存在的值复制到新字段 kubernetes.pod.name 但我需要有条件地执行此操作,因为 pod 名称会不断变化。

如何设置条件,如果字段 prometheus.labels.pod 存在,那么我只需要添加一个名为 kubernetes.pod.name 的新字段(两者具有相同的值)

ctx.prometheus?.labels?.namespace== "name_of_namespace"

我们可以做类似的事情

ctx.prometheus?.labels?.pod== "*"

检查该字段是否存在?

【问题讨论】:

    标签: elasticsearch kibana elk


    【解决方案1】:

    如果文本是一个字符串,并且如果它需要设置一个条件,如果它存在,那么最好的方法是在设置处理器中使用以下条件。

    ctx.prometheus?.labels?.namespace!=null
    

    这就是我使用摄取节点管道实现上述场景的方式。

    "set": {
      "field": "kubernetes.pod.name",
      "copy_from": "prometheus.labels.pod",
      "if": "ctx.prometheus?.labels?.pod!=null",
      "ignore_failure": true
    }
    

    【讨论】:

    • 另请注意,copy_from 仅从 ES 7.11 开始支持。
    • 同意这一点。我正在使用最新版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多