elasticsearch 根据Logstash中的事件消息添加字段无效
我已经安装了ELK并在我的机器中工作,但现在我想根据事件消息进行更复杂的过滤和字段添加 具体来说,我想根据消息模式设置“id_error”和“descripcio” 我已经在“logstash.conf”文件中尝试了很多代码组合,但无法获得预期的行为 有人能告诉我我做错了什么,我必须做什么,或者这是不可能的吗?提前谢谢 这是我的“logstash.conf”文件,以及我所做的最后一次测试,没有在Kibana中捕获任何事件:elasticsearch 根据Logstash中的事件消息添加字段无效,elasticsearch,logstash,kibana,logstash-grok,elasticsearch,Logstash,Kibana,Logstash Grok,我已经安装了ELK并在我的机器中工作,但现在我想根据事件消息进行更复杂的过滤和字段添加 具体来说,我想根据消息模式设置“id_error”和“descripcio” 我已经在“logstash.conf”文件中尝试了很多代码组合,但无法获得预期的行为 有人能告诉我我做错了什么,我必须做什么,或者这是不可能的吗?提前谢谢 这是我的“logstash.conf”文件,以及我所做的最后一次测试,没有在Kibana中捕获任何事件: input { file { path =&g
input {
file {
path => "C:\xxx.log"
}
}
filter {
grok {
patterns_dir => "C:\elk\patterns"
match => [ "message", "%{ERROR2:error2}" ]
add_field => [ "id_error", "2" ]
add_field => [ "descripcio", "error2!!!" ]
}
grok {
patterns_dir => "C:\elk\patterns"
match => [ "message", "%{ERROR1:error1}" ]
add_field => [ "id_error", "1" ]
add_field => [ "descripcio", "error1!!!" ]
}
if ("_grokparsefailure" in [tags]) { drop {} }
}
output {
elasticsearch {
host => "localhost"
protocol => "http"
index => "xxx-%{+YYYY.MM.dd}"
}
}
我还尝试了下面的代码,在每个匹配的事件中分别生成了“id_error”和“descripcio”字段,其中包含“[1,2]”和“[error1!!!,error2!!!]”
由于默认情况下“break_on_match”设置为“true”,我希望只获取匹配子句后面的字段,但这不会发生
input {
file {
path => "C:\xxx.log"
}
}
filter {
grok {
patterns_dir => "C:\elk\patterns"
match => [ "message", "%{ERROR1:error1}" ]
add_field => [ "id_error", "1" ]
add_field => [ "descripcio", "error1!!!" ]
match => [ "message", "%{ERROR2:error2}" ]
add_field => [ "id_error", "2" ]
add_field => [ "descripcio", "error2!!!" ]
}
if ("_grokparsefailure" in [tags]) { drop {} }
}
output {
elasticsearch {
host => "localhost"
protocol => "http"
index => "xxx-%{+YYYY.MM.dd}"
}
}
我已经解决了这个问题。我使用“logstash.conf”中的以下代码获得了预期的结果:
add_字段(和add_标记)只有在过滤器本身成功时才会运行,因此如果您的grok{}与模式不匹配,则不会添加该字段。我已分别检查了所有不同的错误模式,并且所有错误模式都成功,所以这不是问题所在。因此,您的输出包含error1和error2字段?是的,当然,但这不是问题所在。我的意思是,对于每个匹配事件,无论是“error1”模式还是“error2”模式,我都会在字段“id\u error”和“descripcio”中得到一个值列表,比如id\u error=[1,2],descripcio=[error1!!!,error2!!!]。这可能意味着两个搜索都是匹配的,所以两个add\u字段都会运行,从而在字段外创建一个数组。
input {
file {
path => "C:\xxx.log"
}
}
filter {
grok {
patterns_dir => "C:\elk\patterns"
match => [ "message", "%{ERROR1:error1}" ]
match => [ "message", "%{ERROR2:error2}" ]
}
if [message] =~ /error1_regex/ {
grok {
patterns_dir => "C:\elk\patterns"
match => [ "message", "%{ERROR1:error1}" ]
}
mutate {
add_field => [ "id_error", "1" ]
add_field => [ "descripcio", "Error1!" ]
remove_field => [ "message" ]
remove_field => [ "error1" ]
}
}
else if [message] =~ /error2_regex/ {
grok {
patterns_dir => "C:\elk\patterns"
match => [ "message", "%{ERROR2:error2}" ]
}
mutate {
add_field => [ "id_error", "2" ]
add_field => [ "descripcio", "Error2!" ]
remove_field => [ "message" ]
remove_field => [ "error2" ]
}
}
if ("_grokparsefailure" in [tags]) { drop {} }
}
output {
elasticsearch {
host => "localhost"
protocol => "http"
index => "xxx-%{+YYYY.MM.dd}"
}
}