使用logstash创建新字段

时间:2016-05-04 15:02:00

标签: logstash logstash-grok logstash-file

我有一个名为“Job Code.txt”的文件

job_id=0001,description=Ship data from server to elknode1,result=OK
job_id=0002,description=Ship data from server to elknode2,result=Error: Msg...
job_id=0003,description=Ship data from server to elknode3,result=OK
job_id=0004,description=Ship data from server to elknode4,result=OK

这是我的.conf文件的过滤器部分,但它不起作用。如何创建新字段,即jobID,描述,结果以便在kibana中看到

filter{
grok{   match => {"message" => ["JobID: %{NOTSPACE:job_id}","description: %{NOTSPACE:description}","result: %{NOTSPACE:message}"]}
add_field => {
"JobID" => "%{job_id}"
"Description" => "%{description}"
"Message" => "%{message}"
}
}
if [job_id] == "0001" {
aggregate {
task_id => "%{job_id}"
code => "map['time_elasped']=0"
map_action => "create"
}
}
if [job_id] == "0003" {
aggregate {
task_id => "%{job_id}"
code => "map['time_elasped']=0"
map_action => "update"
}
}
if [job_id] == "0002" {
aggregate {
task_id => "%{job_id}"
code => "map['time_elasped']=0"
map_action => "update"
}
}

1 个答案:

答案 0 :(得分:0)

我知道这已经有几天了,也许你还需要答案。将您的grok语句更改为:

grok {
      match => { "message" => "job_id=%{DATA:job_id},description=%{DATA:description},result=%{GREEDYDATA:message}" }
}   

你不需要add_field选项,grok会为你创建它们。 add_field选项用于添加任意字段。检查https://grokdebug.herokuapp.com

处的模式

此外,除非您想要匹配其他消息,否则我认为您所拥有的汇总语句不会达到您想要的效果。