我正在运行ELK进行日志分析。我一切正常。我只想做一些调整。对于所有stackoverflow中的ES / ELK众神,我对此表示感谢。我很高兴为您买杯咖啡! :D
例:
网址:/origina-www.domain.com/this/is/a/path?page=2
首先,我想获得如上所述的完整路径。
其次,我只想获取参数之前的路径:/origina-www.domain.com/this/is/a/path
第三,我只想获取参数:?page = 2
第四,我想使日志文件上的时间戳成为kibana上的主要时间戳。目前,时间戳记kibana显示的是ES处理的日期和时间。
这是示例条目的样子:
2016-10-19 23:57:32 192.168.0.1 GET /origin-www.example.com/url 200 1144 0 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" "-" "-"
这是我的配置:
if [type] == "syslog" {
grok {
match => ["message", "%{IP:client}\s+%{WORD:method}\s+%{URIPATHPARAM:request}\s+%{NUMBER:bytes}\s+%{NUMBER:duration}\s+%{USER-AGENT}\s+%{QS:referrer}\s+%{QS:agent}%{GREEDYDATA}"]
}
date {
match => [ "timestamp", "MMM dd, yyyy HH:mm:ss a" ]
locale => "en"
}
}
ES版本:5.0.1
Logstash版本:5.0
基巴纳语:5.0
更新:我实际上可以通过使用以下方法解决它:
grok {
match => ["message", "%{IP:client}\s+%{WORD:method}\s+%{URIPATHPARAM:request}\s+%{NUMBER:bytes}\s+%{NUMBER:duration}\s+%{USER-AGENT}\s+%{QS:referrer}\s+%{QS:agent}%{GREEDYDATA}"]
}
grok {
match => [ "request", "%{GREEDYDATA:uri_path}\?%{GREEDYDATA:uri_query}" ]
}
kv {
source => "uri_query"
field_split => "&"
target => "query"
}
最佳答案
为了使用日志条目的实际timestamp
而不是索引时间,您可以使用date
和mutate
插件来覆盖现有的timestamp
值。您可以使用logstash
过滤器外观,如下所示:
//filtering your log file
grok {
patterns_dir => ["/pathto/patterns"] <--- you could have a pattern file with such expression LOGTIMESTAMP %{YEAR}%{MONTHNUM}%{MONTHDAY} %{TIME} if you have to change the timestamp format.
match => { "message" => "^%{LOGTIMESTAMP:logtimestamp}%{GREEDYDATA}" }
}
//overriding the existing timestamp with the new field logtimestamp
mutate {
add_field => { "timestamp" => "%{logtimestamp}" }
remove_field => ["logtimestamp"]
}
//inserting the timestamp as UTC
date {
match => [ "timestamp" , "ISO8601" , "yyyyMMdd HH:mm:ss.SSS" ]
target => "timestamp"
locale => "en"
timezone => "UTC"
}
您也可以继续了解Question。希望能帮助到你。
关于elasticsearch - 从URL GROK模式中提取参数(子字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40681814/