简体   繁体   English

Filebeat自定义字段上的Logstash条件逻辑

[英]Logstash conditional logic on custom field from Filebeat

I'm new to ELK stack and am starting out by pushing the IIS logs on my Windows Server 2012 application server to Elastic Search using Filebeat and Logstash. 我是ELK堆栈的新手,并且开始使用Filebeat和Logstash将Windows Server 2012应用程序服务器上的IIS日志推送到Elastic Search。

I plan on extending this so that it also pushes up custom application logs which are written by our applications (as opposed to IIS). 我打算对其进行扩展,以便它也可以推送由我们的应用程序(而不是IIS)编写的自定义应用程序日志。 To do this I'll need to differentiate one type of log from another in Logstash. 为此,我需要在Logstash中将一种日志与另一种日志区分开。

So in filebeat.yml I have added a custom field called "log_type": 因此,在filebeat.yml中,我添加了一个名为“ log_type”的自定义字段:

  type: log
  enabled: true
  paths:
     - C:\inetpub\logs\LogFiles\*\*
  fields:
    log_type: iis

In my Logstash I'm trying to perform some conditional logic based on the value of "log_type" but it's not working. 在我的Logstash中,我试图基于“ log_type”的值执行一些条件逻辑,但是它不起作用。 If I remove the conditional logic the filter works. 如果我删除条件逻辑,则过滤器将起作用。

filter {
  if [fields.log_type] == "iis" {
    grok {
      match => { "message" => "%{TIMESTAMP_ISO8601:log_timestamp} %{IPORHOST:site} %{WORD:method} %{URIPATH:page} %{NOTSPACE:querystring} %{NUMBER:port} %{NOTSPACE:username} %{IPORHOST:clienthost} %{NOTSPACE:useragent} %{NOTSPACE:referer} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:scstatus} %{NUMBER:timetaken:int}"}
    }
    date {
        match => [ "log_timestamp", "ISO8601" ]
        target => "@timestamp"
    }
  }
}

I've searched and searched but can't find out how to do this. 我已经搜索了,但是找不到如何执行此操作。 Would really appreciate some help. 非常感谢您的帮助。

To access the field in Logstash the syntax should be [fields][log_type] rather than [fields.log_type] . 要访问Logstash中的字段,语法应为[fields][log_type]而不是[fields.log_type] [fields][log_type] [fields.log_type]

Reference 参考

Do you have this line in your configuration? 您的配置中是否有此行? fields_under_root: true . fields_under_root: true If yes, you can try simply [log_type] , without any prefixes. 如果是,则可以尝试[log_type] ,不带任何前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM