Logstash - 是否可以根据数据选择不转发日志?

Logstash - Can choose not to forward a log based on data?

刚刚学习如何使用 Logstash - 该死的,这方面有很多东西要学 :D

在我的设置中,我将 CEF 数据发送到我的 logstash。 一些 cef 事件只是关于发送 cef 事件的工具的 "statistic" 信息。

我希望 logstash 不发送这些事件。这可能吗?

这是我认为的一些伪代码。

input { 
  udp { 
    port => 9001 
    codec => cef
}

filter { 
  if 'stat_heading' contains "Statistic Information" do not forward to elasticsearch 
}

output { 
  elasticsearch { 
    host => ["192.168.0.20:9200"] 
}

有人能给我指出正确的方向吗?

编辑

好的 - 所以我看到过滤器确实有一个可选的 IF 条件。我将进一步阅读它,当我得到一个可行的解决方案时,我会 post 它。

编辑

成功了。在下面的评论中添加了解决方案。

我想你可以尝试使用 drop plugin 来跳过一些需要过滤的数据

https://www.elastic.co/guide/en/logstash/current/plugins-filters-drop.html

好的,我已经找到了自己的答案。

您需要添加条件 If 语句,如果事件值与某个值匹配,则删除该事件。

input { 
  udp { 
    port => 9001 
    codec => cef
}

filter { 
  if "Some string here" in [myheader] {
    drop {}
}

output { 
  elasticsearch { 
    host => ["192.168.0.20:9200"] 
}