问题描述
我需要使用grok过滤apache错误日志。 请帮我解决我无法创建的模式!。
我的样本日志:
2020-10-07T01:21:26.403-0400 ERROR [reload] cfgfile/list.go:96 Error creating runner from config: Error getting config for fileset system/auth: Error interpreting the template of the inp$
2020-10-07T01:21:36.404-0400 ERROR [reload] cfgfile/list.go:96 Error creating runner from config: Error getting config for fileset system/auth: Error interpreting the template of the inp$
2020-10-07T01:21:38.925-0400 ERROR pipeline/output.go:100 Failed to connect to backoff(async(tcp://IP:5044)): dial tcp IP:5044: I/O timeout
2020-10-07T01:21:38.925-0400 INFO pipeline/output.go:93 Attempting to reconnect to backoff(async(tcp://IP:5044)) with 26743 reconnect attempt(s)
2020-10-07T01:21:38.925-0400 INFO [publish] pipeline/retry.go:189 retryer: send unwait-signal to consumer
2020-10-07T01:21:38.925-0400 INFO [publish] pipeline/retry.go:191 done
2020-10-07T01:21:38.925-0400 INFO [publish] pipeline/retry.go:166 retryer: send wait signal to consumer
2020-10-07T01:21:38.925-0400 INFO [publish] pipeline/retry.go:168 done
我了解了grok模式,我们可以在下面使用它们,但是我不了解如何在Grok Pattern中使用它:
# Error logs
HTTPD20_ERRORLOG \[%{HTTPDERROR_DATE:timestamp}\] \[%{LOGLEVEL:loglevel}\] (?:\[client %{IPORHOST:clientip}\] ){0,1}%{GREEDYDATA:message}
HTTPD24_ERRORLOG \[%{HTTPDERROR_DATE:timestamp}\] \[%{WORD:module}:%{LOGLEVEL:loglevel}\] \[pid %{POSINT:pid}(:tid %{NUMBER:tid})?\]( \(%{POSINT:proxy_errorcode}\)%{DATA:proxy_message}:)?( \[client %{IPORHOST:clientip}:%{POSINT:clientport}\])?( %{DATA:errorcode}:)? %{GREEDYDATA:message}
HTTPD_ERRORLOG %{HTTPD20_ERRORLOG}|%{HTTPD24_ERRORLOG}
任何人都可以帮忙!预先感谢!
解决方法
处理完样本数据后,该grok模式必须可用:
filter {
grok {
match => { "message" => "%{TIMESTAMP_ISO8601}%{SPACE}%{LOGLEVEL}(%{SPACE}\[%{WORD:action}\])?%{SPACE}%{WORD:package}/%{WORD:class}.go:%{INT:line:number}%{SPACE}%{GREEDYDATA:message}$" }
}
}
您的数据不完全是http,因此需要一个自定义模式,我想我的grok必须更容易阅读而没有空格,我建议您使用mutate-gsub来统一空间(请注意最后一个句子“消息”)。
您具有有关此模式和其他here的更多详细信息。