logstash mutate split日誌切分
阿新 • • 發佈:2019-01-11
通過logstash可以將日誌過濾
(即取到http_request值,如下)
42.62.45.23 - - [15/Jun/2015:10:27:33 +0800] "GET /www/delivery/aj.php?id=29 HTTP/1.1" 200 10309 "-" "-" "10.72.16.60:80" 0.111
72.62.45.23 - - [15/Jun/2015:10:27:33 +0800] "GET /www/delivery/jo.php?id=29 HTTP/1.1" 200 10309 "-" "-" "10.72.16.60:80" 0.111
現在要對紅色框內切分出來
不難看出,紅色框內連結是以問號為分割點的,
這裡我們用到logstash mutate split
官方說明如下
Synopsis
This is what it might look like in your config file:
filter { split { add_field => ... # hash (optional), default: {} add_tag => ... # array (optional), default: [] field => ... # string (optional), default: "message" remove_field => ... # array (optional), default: [] remove_tag => ... # array (optional), default: [] terminator => ... # string (optional), default: "\n" } }
按語法進行切分
mutate {
split => ["http_request" ,"?"] #http_request以問號為切割點
add_field => ["request_url", "%{http_request[0]}"] #取出陣列中第一個值,同時新增request_url為新的field
}
重新啟動logstash,
可以看出,我們的日誌已經成功切分出來了