【发布时间】:2018-04-27 22:50:04
【问题描述】:
我有一个包含复杂消息类型的日志文件。这是一个例子:
2016-07-07 13:30:02 [Main] *** Program start ***
2016-07-07 13:30:02 [UnzipFile] Before file collection
2016-07-07 13:30:02 [GetZipCol] Start get sorted zip file collection
2016-07-07 13:30:02 [GetZipCol] End get sorted zip file collection
2016-07-07 13:30:02 [Main] [ERROR] No unzip file
2016-07-07 13:30:03 [Main] *** Program end ***
下面的 grok 模式只适用于前 4 行,不适用于第 5 行。
grok{
match => {"message" => ['%{Date:Date}%{SPACE}%{Time:Time}%{SPACE}%{WORD:Job}%{SPACE}%{GREEDYDATA:Message}']}
}
我想知道如何将 grok 模式修改为从最后一条消息中捕获[ERROR]。有没有人知道如何做到这一点?
这是我在conf中的输出部分
if [Message] == "*** Program start ***" {
elasticsearch {
hosts => ["localhost:9200"]
index => "log-%{+YYYY.MM.dd}"
template => "C:/logstash/log.json"
template_overwrite => true
}
}
if [Message] == "*** Program end ***" {
elasticsearch {
hosts => ["localhost:9200"]
index => "log-%{+YYYY.MM.dd}"
template => "C:/logstash/log.json"
template_overwrite => true
}
}
if [Level] =~ /.+/ {
elasticsearch {
hosts => ["localhost:9200"]
index => "log-%{+YYYY.MM.dd}"
template => "C:/logstash/log.json"
template_overwrite => true
}
}
如果我只想掌握程序开始和结束时的事件以及错误的事件,而其他事件可以被丢弃。但是,根据我所写的。我只能用[错误]来掌握数据。我还应该如何掌握其他数据?是否有一种更简单的方法来代替输入 3 if 条件语句?谢谢。
谢谢。
【问题讨论】:
-
"我只能用 [Error] 掌握数据" 不是这样,最后一个条件语句意味着你掌握了模式成功解析的所有消息字段
Level -
不是做三个条件,你可以做一个,否定三个不同的条件并丢弃所有通过 =>
if ([Message] != "*** Program start ***" and [Message] != "*** Program end ***" and [Level] !~ /.+/) { drop{} }的消息。然后你使用一个 elasticsearch 输出 -
@baudsp 谢谢,它运作良好。只想知道如何检查消息是否包含“程序”一词而不是整行消息?
-
就像你对
[Level]所做的一样,你可以像这样使用=~比较器:=~ /Program/