我无法在Logstash中拆分http.request.referrer字段。这来自数据包节拍。我只想使用域而不是完整路径。使用以下过滤器(如此处https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html所示),我收到以下错误
[WARN ][logstash.filters.mutate ] Exception caught while applying mutate filter {:exception=>"Invalid FieldReference: `sfa[2]`"}
但是,如果我不尝试检索第二个元素,而只是使用sfa字段添加到sfa_ref,那么它就可以工作,只有正斜杠用逗号代替。
filter {
mutate {
add_field => {"sfa" => "%{[http][request][referrer]}"}
}
mutate {
split => ["sfa", "/"]
add_field => {"sfa_ref" => "%{sfa[2]}"}
}
}
输入如下:
{
"http": {
"request": {
"bytes": 727,
"method": "get",
"headers": {
"content-length": 0
},
"referrer": "https://example.domain.com/web/font-awesome/css/font-awesome.min.css"
},
"response": {
"bytes": 66989,
"status_code": 200,
"body": {
"bytes": 66624
},
"headers": {
"content-length": 66624,
"content-type": "application/font-woff2"
}
},
"version": "1.1"
},
"status": "OK"
}
分割后,sfa
字段变为:
"sfa": [ "https:", "", "example.domain.com", "web", "font-awesome", "css", "font-awesome.min.css" ]
答案 0 :(得分:2)
后面的文档似乎已过时。在较新版本的logstash中,寻址数组或其中的元素的正确方法是%{[field_name][index]}
。
因此,我还需要在字段名称周围加上方括号。
mutate {
split => ["sfa", "/"]
add_field => {"sfa_ref" => "%{[sfa][2]}"}
}