我在让 logstash 识别我的模式时遇到了一些问题,这似乎与 Grok 调试器 ( https://grokdebug.herokuapp.com/ ) 匹配。
这与另一个 StackOverflow 问题(logstash _grokparsefailure 问题)中发现的问题类似,但不幸的是,那里的解决方案似乎不起作用。
这些是我要匹配的日志:
Mon Jan 25 11:12:12.890 [conn44141] authenticate db: admin { authenticate: 1, user: "person", nonce: "f00000000f", key: "a0000000000e" }
"2015-01-25 14:46:31" id=Admin id=Admin,ou=user,dc=gooogle-wa,dc=com a000000a 100.00.00.01 INFO dc=gooooogle-wa,dc=com "cn=user,ou=AME Users,dc=goooogle,dc=com" BARF-4 aO.access "Not Available" 100.00.00.01
我用来解析这些的模式分别是:
if [type] == "openam" {
if [file] =~ "access" {
grok{
match => [ 'message', '\"%{TIMESTAMP_ISO8601:timestamp}\"(\s*)(%{QUOTEDSTRING:data_}|%{DATA:data_})(\s*)(%{QUOTEDSTRING:LoginID}|%{DATA:LoginID})(\s*)%{DATA:ContextID}(\s*)(\"%{DATA:IP}\"|%{IP:IP})(\s*)?%{LOGLEVEL:loglevel}(\s*)%{DATA:Domain}(\s*)\"%{DATA:LoggedBy}\"(\s*)(?<messageID>[a-zA-Z0-9._-]+)(\s*)(%{DATA:ModuleName})(\s*)\"%{DATA:NameID}\"(\s*)(%{IP:hostname}|%{GREEDYDATA:hostname}) '
]
add_tag => "openam_access"
}
}
else if [file] =~ "error" {
grok{
match => ['message', '\"%{TIMESTAMP_ISO8601:timestamp}\"(\s*)(%{QUOTEDSTRING:data_}|%{DATA:data_}) (\s*)(%{QUOTEDSTRING:LoginID}|%{DATA:LoginID}) (\s*)%{DATA:ContextID}(\s*)(\"%{DATA:IP}\"|%{IP:IP})(\s*)?%{LOGLEVEL:loglevel}(\s*)%{DATA:Domain}(\s*)\"%{DATA:LoggedBy}\"(\s*)(?<messageID>[a-zA-Z0-9._-]+)(\s*)(%{DATA:ModuleName})(\s*)\"%{DATA:NameID}\"(\s*)(%{IP:hostname}|%{GREEDYDATA:hostname})',
]
add_tag => "openam_error"
}
}
}
if [type] == "mongo" {
grok {
match => [
"message", "(?m)%{GREEDYDATA} \[conn%{NUMBER:mongoConnection}\] %{WORD:mongoCommand} %{WORD:mongoDatabase}.%{NOTSPACE:mongoCollection} %{WORD}: \{ %{GREEDYDATA:mongoStatement} \} %{GREEDYDATA} %{NUMBER:mongoElapsedTime:int}ms",
"message", "%{DATA:DayOfWeek} %{SYSLOGTIMESTAMP:timestamp} %{DATA:Thread} %{GREEDYDATA:msg} %{IP:ip}:%{NUMBER:port} ?#?%{NUMBER:ID}? %{GREEDYDATA:connections} ",
'message', '%{DATA:DayOfWeek} %{SYSLOGTIMESTAMP:timestamp} %{DATA:Thread} %{DATA:msg}: %{WORD:userType} \{ authenticate: %{NUMBER:authenticate}, user: %{QS:user}, nonce: %{QS:nonce}, key: %{QS:key} \}'
]
add_tag => "mongodb"
}
}
如您所见,这些模式在调试器上可以正常工作,但由于某种原因,在我的 kibana 仪表板上,它们显示为 _grokparsefailure 标记。我怀疑它与我转义字符或使用{QS}/{QOUTEDSTRING}
.
谢谢