我已将 Logstash 配置为过滤httpd_access_log
消息并了解与COMBINEDAPACHELOG
. 但是,我收到如下错误:
[2017-02-10T15:37:39,361][WARN ][logstash.outputs.elasticsearch] Failed action. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"filebeats", :_type=>"logs", :_routing=>nil}, 2017-02-10T23:37:34.187Z perf-wuivcx02.hq.mycompany.com cdn.mycompany.com 192.168.222.60 - - [10/Feb/2017:15:37:30 -0800] "GET /client/asd-client-main.js HTTP/1.1" 200 221430 "http://perf.companysite.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"], :response=>{"index"=>{"_index"=>"filebeats", "_type"=>"logs", "_id"=>"AVoqY6qkpAiTDgWeyMHJ", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [timestamp]", "caused_by"=>{"type"=>"number_format_exception", "reason"=>"For input string: \"10/Feb/2017:15:37:30 -0800\""}}}}}
这是我的 Logstash 过滤器配置:
filter {
if [type] == "json" {
json {
source => "message"
}
}
if [type] == "syslog" {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
if [type] == "httpd_access_log" {
grok {
match => { "message" => "%{URIHOST} %{COMBINEDAPACHELOG}" }
}
date {
match => [ "timestamp", "MMM dd yyyy HH:mm:ss", "MMM d yyyy HH:mm:ss", "ISO8601" ]
}
}
}
该date
函数适用于处理syslog
类型消息,但不适用于httpd_access_log
消息。有谁知道为什么时间戳会导致httpd_access_log
文件中的行无法在 Elasticsearch 中建立索引?
提前感谢您提供的任何帮助或建议!
这不是 100% 的过滤器问题,输出只是症状。以下是向您显示此错误消息的关键部分。
这告诉您失败的插件是 elasticsearch 输出。
(为了清楚起见,剪掉了)那是在尝试
index
对 ElasticSearch 执行操作。这里发生的是
timestamp
索引中的字段不接受您尝试放入其中的字符串。number_format_exception
它说ElasticSearch 期望非字符串作为输入的事实。Logstash 正在尝试将字符串写入该
timestamp
字段。这表明该timestamp
字段实际上并未通过date {}
过滤器。这表明if [type] == "httpd_access_log" {
没有捕捉到所有可能的实例timestamp
,或者您的日期过滤器的模式没有捕捉到这个。错误字符串已清除,但我不确定您的来源是否真的发出时间戳,例如:如果它真的像那样进入管道,找出原因。