我尝试将 logstash 集成到我们的应用程序中,其中我在 custompattern 文件中包含以下模式。
Path: <path>/custom_pattern -- This is custom pattern file. I include this path in conf.
Content: ACCESSLOGPARSE \[%{HTTPDATE:timestamp}\] %{IPORHOST:clientip} (?: xff=%{IPORHOST:xffIp})
我的logstash conf文件:
input {
file{
path => "/tmp/jboss-logs.log"
start_position => beginning
}
}
filter {
if [path] =~ "jboss" {
mutate { replace => { "type" => "jboss_access"}}
grok {
patterns_dir => "<dir path>"
match => { "message" => "%{ACCESSLOGPARSE}" }
}
}
date {
match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
output {
elasticsearch { host => localhost }
stdout { codec => rubydebug }
}
我的 jboss-logs.log 文件内容:
[09/Jan/2015:00:00:02 +0000] 127.0.0.1 xff=-
[09/Jan/2015:00:10:17 +0000] 100.20.10.11 xff=100.40.11.3
当我执行 logstash 时,我得到以下未解析日志的输出。
{
"message" => "[09/Jan/2015:00:00:02 +0000] 127.0.0.1 xff=-",
"@version" => "1",
"@timestamp" => "2015-01-20T15:30:10.865Z",
"host" => "Salvador",
"path" => "/tmp/jboss-logs.log",
"type" => "jboss_access",
"tags" => [
[0] "_grokparsefailure"
]
}
{
"message" => "[09/Jan/2015:00:10:17 +0000] 100.20.10.11 xff=100.40.11.3",
"@version" => "1",
"@timestamp" => "2015-01-20T15:30:10.869Z",
"host" => "Salvador",
"path" => "/tmp/jboss-logs.log",
"type" => "jboss_access",
"tags" => [
[0] "_grokparsefailure"
]
}
问题是日志中的“xff”键可能包含 ip 或“-”。我也尝试过以下模式。但他们也没有工作。
ACCESSLOGPARSE \[%{HTTPDATE:timestamp}\] %{IPORHOST:clientip} (?: xff=%{IPORHOST:xffIp}|-)
and
ACCESSLOGPARSE \[%{HTTPDATE:timestamp}\] %{IPORHOST:clientip} (?: xff=%{IPORHOST:xffIp}|xff=-)
这种模式的解析器有什么问题?