繁体   English   中英

Logstash,如何使用来自事件数据的grok模式

[英]Logstash, how to use grok patterns coming from event data

我在kubernetes上部署了一个ELK堆栈,用于收集容器的数据。 在所有其他方法中,它使用grok过滤器根据模式分析实际的日志行。

我希望能够通过使用kubernetes窗格中的注释来设置此模式。

我在pod添加了一个名为elk-grok-pattern的注释,配置了filebeat以便转发该注释,到目前为止,我在logstash中的event中可以将注释值作为字段获取。

问题是我无法将字段的值用作grok pattern

我的广告连播中的注解如下:

Annotations:    elk-grok-pattern=%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:status} %{NUMBER:response_time}

我尝试使用的filter类似于以下内容:

filter {
  # create a new field called "elk-grok-pattern" from the pod annotation
  mutate {
        rename => { "[kubernetes][annotations][elk-grok-pattern]" => "elk-grok-pattern" }
  }

  grok {
    pattern_definitions => {
      "CUSTOM" => "%{elk-grok-pattern}"
    }
    match => { "log" => "%{CUSTOM}" }
  }
}

不幸的是,这会导致错误:

Pipeline aborted due to error {:pipeline_id=>"main", :exception=>#<Grok::PatternError: pattern %{elk-grok-pattern} not defined>

实际上,grok是按字面解释我的模式,而不是评估事件产生的字符串内容。

我还尝试直接使用模式,而无需定义pattern_definition,如下所示:

grok {
  match => { "log" => "%{elk-grok-pattern}" }
}

但是我得到同样的错误。

有没有办法实现我的目标? 任何建议或可能的解决方法将不胜感激。

如果您不希望在其他地方使用此模式,为什么不在这样的比赛中使用它呢?

grok {
  match => { "log" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:status} %{NUMBER:response_time}" }
}

如果您想稍后在其他过滤器中使用它,请查看此页面上的模式创建:
https://www.elastic.co/guide/zh-CN/logstash/current/plugins-filters-grok.html#setting_patterns_dir

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM