什么是grok过滤器

时间:2016-07-12 06:24:35

标签: logstash logstash-grok kibana-3

这是以下json示例,其中我想基于客户端ID和用户ID(中的消息标记中的过滤和索引

filter {
  grok {

match => {
        "message" => "Uri: %{URIPATHPARAM:url}%{SPACE}Ip: %{IP:ip},%{SPACE}User id: %{WORD:Userid}, Client id:%{WORD:Clientid}"
}

 }
}

我想根据客户端ID和用户ID索引用户活动。我在logstash conf中的过滤器是:

Warning: mcrypt_decrypt(): Key of size 21 not supported by this algorithm

2 个答案:

答案 0 :(得分:0)

您可以使用此grok过滤器:

grok {
    match => {
        "message" => [
            "%{MONTHDAY} %{MONTH} %{YEAR} %{TIME} %{GREEDYDATA} \[%{DATA}\]%{SPACE}%{WORD}%{SPACE}- Request details - Uri: %{URIPATH}, Ip: %{IP}, User id: %{NUMBER:user_id}, Client id: %{NUMBER:client_id}"
        ]
    }
}

注意:我删除了**User id周围的Client id,因为它似乎只是强调日志行的有趣部分。 但如果您的日志中确实有**,则必须使用以下代码修改模式:\*\*User id:\*\* %{NUMBER:user_id}, \*\*Client id:\*\*%{NUMBER:client_id}

答案 1 :(得分:0)

这有效!!

  filter {
      if [type] == "corporate-access" {
        grok {
          break_on_match => false
          match => { "message" => "Uri: %{URIPATHPARAM:url}%{SPACE}" }
           match => { "message" => "User id: %{WORD:Userid}, Client id:%{WORD:Clientid}" }
           add_tag => "%{Userid}"
           add_tag => "%{Clientid}"
           add_tag => "%{url}"

        }
      }