Logstash + nginx:没有添加字段

rhfm7lfc  于 5个月前  发布在  Logstash
关注(0)|答案(1)|浏览(75)

我打算安装我自己的ELK服务器来集中日志记录。到目前为止一切顺利。
我设置了docker-compose.yml来运行ELK栈,另一个docker-compose.yml来运行filebeat,它将监视日志文件,添加env +标签并发送到logstash。解析应该在logstash中进行。
filebeat.yml

name: xyz

fields:
  env: xyz

output.logstash:
  hosts: ["xyz:5044"]

filebeat.prospectors:
  - input_type: log
    fields:
      app_id: default
      type: nginx-access
    tags:
      - nginx
      - access
    paths:
      - /logs/nginx/access.log*
  - input_type: log
    fields:
      app_id: default
      type: nginx-error
    tags:
      - nginx
      - error
    paths:
      - /logs/nginx/error.log*

字符串
这里是logstash.yml

input {
  beats {
    port => 5044
  }
}

filter {
  if ["nginx"] in [tags] and ["access"] in [tags] {
    grok {
      patterns_dir => "/etc/logstash/patterns"
      match => { "message" => "%{NGINXACCESS}" }
    }

    date {
      match => [ "timestamp", "dd/MMM/YYYY:HH:mm:ss Z" ]
    }
  }
}

output {
  elasticsearch {
    hosts => ["elasticsearch:9200"]
  }
  stdout { codec => rubydebug }
}


nginx模式在这里

NGUSERNAME [a-zA-Z\.\@\-\+_%]+
NGUSER %{NGUSERNAME}
NGINXACCESS %{IPORHOST:clientip} %{NGUSER:indent} %{NGUSER:agent} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{URIPATHPARAM:request}(?: HTTP/%{NUMBER:httpversion})?|)\" %{NUMBER:answer} (?:%{NUMBER:byte}|-) (?:\"(?:%{URI:referrer}|-))\" (?:%{QS:referree}) %{QS:agent}


我在grokconstructor.appspot.com上测试了这个表达式,它成功了。
下面是一个演示行:

127.0.0.1 - - [11/May/2017:13:49:31 +0200] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586" "-"


但没有添加字段
x1c 0d1x的数据
我想也许我的“如果”是错误的,但我尝试了几种替代方案.没有帮助。
你知道吗?

0qx6xfy6

0qx6xfy61#

我将从删除if开始,然后逐个添加条件。

["nginx"] in [tags]

字符串
如果成功的话,

["nginx"] in [tags] and ["access"] in [tags]


或者,您可以尝试使用

"nginx" in [tags] and "access" in [tags]

更新:

到已使用的字段。type = nginx访问,尝试

"nginx-access" in [fields][type]

相关问题