【问题标题】:Logstash: Unable to filter apache vhost_combined custom log and post them into ElasticsearchLogstash:无法过滤 apache vhost_combined 自定义日志并将其发布到 Elasticsearch
【发布时间】:2025-12-22 14:15:11
【问题描述】:

我需要使用 Geo IP 过滤以下 apache vhost 日志格式。这样grok才能理解并顺利工作。

确切的日志格式:

LogFormat "%V:%p %h %l %u %t \"%r\" %>s %O %T %D \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined_custom

您会看到 %T 和 %D 标志在这里是多余的。

消息:

sub1.example.com:443 1.9.202.41 - - [03/Jun/2016:06:58:17 +0000] "GET /notifications/pendingCount HTTP/1.1" 200 591 0 32165 "https://sub1.example.com/path/index?var=871190" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"

有什么建议吗?

【问题讨论】:

    标签: logstash logstash-grok elastic-stack filebeat


    【解决方案1】:

    你也可以这样做:

    match => { "message" => "%{HOSTNAME:vhost}\:%{NUMBER:port} %{COMBINEDAPACHELOG}"}
    

    根据Rene's blog

    【讨论】:

      【解决方案2】:

      好的,经过多次测试,我找到了解决方案。应该是这样的:

      grok {                                                                                           
            match => { "message" => "%{IPORHOST:vhost}:%{POSINT:port} %{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})\" %{NUMBER:response} %{NUMBER:bytes} %{NUMBER:seconds} %{NUMBER:microseconds} %{QS:referrer} %{QS:agent}" }
      }
      

      【讨论】:

        最近更新 更多