Logstash _使用多个grok筛选器分析的所有日志中的grokparsefailure标记

Logstash _使用多个grok筛选器分析的所有日志中的grokparsefailure标记,logstash,elastic-stack,logstash-grok,logstash-configuration,Logstash,Elastic Stack,Logstash Grok,Logstash Configuration,我试图用弹性堆栈解析minecraft日志,我遇到了一个非常奇怪的问题(可能对我来说很奇怪!) 我的日志的所有行都得到了正确的解析,但我在每个行中都得到了\u grokparsefailure标记 我的日志存储管道配置如下: input { file { path => [ "/path/to/my/log" ] #start_position => "beginning" tags => ["min

我试图用弹性堆栈解析minecraft日志,我遇到了一个非常奇怪的问题(可能对我来说很奇怪!)

我的日志的所有行都得到了正确的解析,但我在每个行中都得到了
\u grokparsefailure
标记

我的日志存储管道配置如下:

input {
  file {
    path => [ "/path/to/my/log" ]
    #start_position => "beginning"
    tags => ["minecraft"]
  }
}

filter {
  if "minecraft" in [tags] {

#    mutate {
#      gsub => [
#        "message", "\\n", ""
#      ]
#    }



    #############################
    #           Num 1           #
    #############################
    grok {
      match => [ "message", "\[%{TIME:timestamp}] \[(?<originator>[^\/]+)?/%{LOGLEVEL:level}]: %{GREEDYDATA:message}" ]
      overwrite => [ "message" ]
      break_on_match => false
    }


    #############################
    #           Num 2           #
    #############################
    grok {
      match => [ "message", "UUID of player %{USERNAME} is %{UUID}" ]
      add_tag => [ "player", "uuid" ]
      break_on_match => true
    }


    #############################
    #           Num 3           #
    #############################
    grok {
      match => [ "message",  "\A(?<player>[a-zA-Z0-9_]+)\[/%{IPV4:ip_address}:%{POSINT}\] logged in with entity id %{POSINT:entity_id} at \(\[(?<world>[a-zA-Z]+)\](?<pos>[^\)]+)\)\Z" ]
      add_tag => [ "player", "join" ]
      break_on_match => true
    }
#
#    grok {
#      match => [ "message",  "^(?<player>[a-zA-Z0-9_]+) has just earned the achievement \[(?<achievement>[^\[]+)\]$" ]
#      add_tag => [ "player", "achievement" ]
#    }
#
#    grok {
#      match => [ "message", "^(?<player>[a-zA-Z0-9_]+) left the game$" ]
#      add_tag => [ "player", "part" ]
#    }
#
#    grok {
#      match => [ "message", "^<(?<player>[a-zA-Z0-9_]+)> .*$" ]
#      add_tag => [ "player", "chat" ]
#    }
  }
}

output {
        elasticsearch {
                hosts => ["elasticsearch:xxxx"]
                user => "xxxx"
                password => "xxxxxx"
        index => "minecraft_s1v15_%{+YYYY.MM.dd}"
        }
}
输入{
文件{
路径=>[“/path/to/my/log”]
#开始位置=>“开始”
标签=>[“地雷船”]
}
}
滤器{
如果[标签]中有“地雷船”{
#变异{
#gsub=>[
#“消息”、“\\n”、“
#      ]
#    }
#############################
#数字1#
#############################
格罗克{
匹配=>[“消息”,“\[%{TIME:timestamp}]\[(?[^\/]+)?/%{LOGLEVEL:level}]:%{greedyddata:message}]
覆盖=>[“消息”]
在匹配时中断匹配=>false
}
#############################
#数字2#
#############################
格罗克{
match=>[“消息”,“玩家%{USERNAME}的UUID为%{UUID}”]
添加标签=>[“玩家”,“uuid”]
在匹配时中断匹配=>true
}
#############################
#数字3#
#############################
格罗克{
match=>[“message”,“\A(?[A-zA-Z0-9\]+)\[/%{IPV4:ip地址}:%{POSINT}\]以实体id%{POSINT:entity\u id}登录在\(\[(?[A-zA-Z]+)\](?[^\]+)\\Z”]
添加标签=>[“玩家”,“加入”]
在匹配时中断匹配=>true
}
#
#格罗克{
#match=>[“message”,“^(?[a-zA-Z0-9_]+)刚刚获得了成果\[(?我在grok筛选器之前添加了
mutate
块(导致日志的每一行都以\n结尾),但没有任何更改,问题仍然存在


我认为我需要提到的另一件事是,我知道在grok 2(3和其他)之外添加更多的grok会导致此标记导致一些日志根本不匹配grok 2,并且必须用正则表达式包装它们。但是至少现在匹配grok 2的日志应该是可以的(不
\grokparsefailure
),但它们不是!(在stackoverflow问题中阅读:

事实上,这是预期的行为,您对logstash和grok的工作方式有点混淆

首先,所有过滤器都是相互独立的,在
grok
中使用
break\u on\u match
只会影响
grok
,这对管道中随后出现的其他
grok
过滤器没有影响。
break\u on\u match
也只有在sa中有多个模式时才有意义me
grok
,这不是你的情况

其次,由于Logstash是串行的,并且您没有使用任何条件,因此您的
grok
过滤器将应用于管道中的每一条消息,不管它是否已被解析,这就是让您的行获取
\u grokparsefailure

要解决这个问题,您需要使用条件句

在前两个
grok
过滤器中不需要条件,第一个只是获取日志行的不同部分并覆盖到
消息
字段中,第二个只是第一次测试,对于第二个过滤器之后的每个
grok
,您都需要以下配置

if "_grokparsefailure" in [tags] {
  grok {
    match => "your pattern"
    add_tag => "your tags"
    remove_tag => ["_grokparsefailure"]
  }
}
grok
仅当消息在
标记
字段中有
\u grokparsefailure
时才会应用,如果消息与您的模式匹配,此标记将被删除,如果不匹配,标记将保留,并且可以通过以下grok测试消息

最后,您的
grok
配置应该是这样的

grok {
  "your first grok"
}

grok {
  "your second grok, can be any of the others"
}

if "_grokparsefailure" in [tags] {
  grok {
    "your grok N"
    remove_tag => ["_grokparsefailure"]
  }
}
这仅仅是因为您要为每条消息添加不同的标记,例如,如果您将此逻辑移动到
mutate
过滤器,您只能使用两个
grok
过滤器,第二个过滤器将是多模式
grok
,其中
break\u on\u match
设置为
true

grok {
  match => { 
    "message" => [ 
      "pattern from grok 2",
      "pattern from grok 3",
      "pattern from grok N"
    ]
  }
  break_on_match => true
}

事实上,这是预期的行为,您对logstash和grok的工作方式有点困惑

首先,所有过滤器都是相互独立的,在
grok
中使用
break\u on\u match
只会影响
grok
,这对管道中随后出现的其他
grok
过滤器没有影响。
break\u on\u match
也只有在sa中有多个模式时才有意义me
grok
,这不是你的情况

其次,由于Logstash是串行的,并且您没有使用任何条件,因此您的
grok
过滤器将应用于管道中的每一条消息,不管它是否已被解析,这就是让您的行获取
\u grokparsefailure

要解决这个问题,您需要使用条件句

在前两个
grok
过滤器中不需要条件,第一个只是获取日志行的不同部分并覆盖到
消息
字段中,第二个只是第一次测试,对于第二个过滤器之后的每个
grok
,您都需要以下配置

if "_grokparsefailure" in [tags] {
  grok {
    match => "your pattern"
    add_tag => "your tags"
    remove_tag => ["_grokparsefailure"]
  }
}
grok
仅当消息在
标记
字段中有
\u grokparsefailure
时才会应用,如果消息与您的模式匹配,此标记将被删除,如果不匹配,标记将保留,并且可以通过以下grok测试消息

最后,您的
grok
配置应该是这样的

grok {
  "your first grok"
}

grok {
  "your second grok, can be any of the others"
}

if "_grokparsefailure" in [tags] {
  grok {
    "your grok N"
    remove_tag => ["_grokparsefailure"]
  }
}
这仅仅是因为您要为每条消息添加不同的标记,例如,如果您将此逻辑移动到
mutate
过滤器,您只能使用两个
grok
过滤器,第二个过滤器将是多模式
grok
,其中
break\u on\u match
设置为
true

grok {
  match => { 
    "message" => [ 
      "pattern from grok 2",
      "pattern from grok 3",
      "pattern from grok N"
    ]
  }
  break_on_match => true
}