基于过滤器的Logstash索引

chhqkbe1  于 2022-12-09  发布在  Logstash
关注(0)|答案(1)|浏览(181)

嗨,我正在阅读stdout,并使用logstash过滤Apache和应用程序日志,如下所示

input {
 beats {
 port => 5044
 }
}
filter {
  grok {
   match => { "message" => "%{COMBINEDAPACHELOG}"}
  }
  json {
   source => "message"
  }
}
output { elasticsearch { hosts => "http://elasticsearch-master:9200"} }

这些日志正确地到达ElasticSearch,但是我如何在es中为apache和logstash输出中的应用程序日志给予单独的索引?

cvxl0en2

cvxl0en21#

您可以在输入插件中使用“类型”来分隔这些。您可以尝试以下注意:假设日志是apache日志

input {
 beats {
 port => 5044
#assuming that your log is apache
 type => "apache" 
 }
}

filter {
  grok {
   match => { "message" => "%{COMBINEDAPACHELOG}"}
  }
  json {
   source => "message"
  }
}


output {  
    stdout {codec => rubydebug}

    if [type] == "apache" {
        elasticsearch {  
            hosts => "http://elasticsearch-master:9200"  
            index => "apache_index"   
        }
    } 

    else {
        elasticsearch {  
            hosts => "http://elasticsearch-master:9200"  
            index => "application_index"   
        }
    }
}

请随时关注!谢谢!

相关问题