[英]logstash / grok custom fileds
I'm a totally new user of ELK stack. 我是ELK堆栈的全新用户。 I've got a little problem with filtering out specific section from my log.
我从日志中过滤出特定部分时遇到了一些问题。
Sample log: 样本日志:
[2017-05-30 13:58:09,336] INFO [com.qwerty.test.core.services.impl.order.OrderEntryService] (OrderEntryService.java:5426) [http-/0.0.0.0:1111-111] {{CT,1496145487308}{IP,111.11.111.11}{JTX,1511059/176275501}{OBJT,goodsMovement.reportsUtils.ConsignmentStocksList}{OPT,SQ}{PID,111111}{SS,SSCPLTMPRODPL}{TRT,SAP_LOGISTIC_REPORT}{UID,StudentSaSo-8}}: Saving order: K1010101
and my grok filter: 和我的希腊过滤器:
grok {
match => { "message" => "(?<timestamp>%{YEAR}-%{MONTHNUM2}-%{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND},%{NONNEGINT})\] %{LOGLEVEL:loglevel} * \[(?<logger>[A-Za-z0-9$_.]+)\] \(%{JAVAFILE:class}:%{NONNEGINT:line}\) \[%{NOTSPACE:thread}\] %{GREEDYDATA:message_TEST}"}
}
so i need filter out "ID", "PID", IP and "UID" and i have no idea how to configure this specific custom pattern. 所以我需要过滤掉“ ID”,“ PID”,IP和“ UID”,而且我不知道如何配置此特定的自定义模式。 I try use patterns from https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns but it does not work for me
我尝试使用https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns中的模式,但对我不起作用
The beginning of your grok is fine. 骗子的开始很好。 Instead of the last part
%{GREEDYDATA:message_TEST}
, which will just save the remainder of your message into message_TEST
you should actually perform parsing of your object. 而不是最后一部分
%{GREEDYDATA:message_TEST}
, %{GREEDYDATA:message_TEST}
会将剩余的消息保存到message_TEST
您实际上应该执行对象的解析。 Something like this will save PID
, IP
and UID
fields from your object into respective variables (keep in mind that this pattern relies on the fields order): 这样的事情会将对象中的
PID
, IP
和UID
字段保存到各自的变量中(请注意,此模式取决于字段顺序):
{{.*}{IP,%{IPV4:IP}}({.*}){3}{PID,%{POSINT:PID}}({.*}){2}{UID,%{DATA:UID}}}
Now a little explanation of what it does. 现在对它的作用进行一些解释。 Outer pair of curly brackets is the limit of your object.
一对大括号是对象的限制。 Then we will take care of each field limited by pair of curly brackets inside of the object.
然后,我们将处理受对象内部一对大括号限制的每个字段。
{
; {
; {CT,1496145487308}
, we are not interested in saving it - so just tell grok that there's some string limited by curly brackets: {.*}
; {CT,1496145487308}
,我们对保存它不感兴趣-因此,请告诉grok某些字符串受大括号限制: {.*}
; {IP,111.11.111.11}
. {IP,111.11.111.11}
。 It starts with curly bracket and IP,
followed by IP address that we have to save (last IP in the match is the name of variable that will store the IP address): {IP,%{IPV4:IP}
IP,
开头IP,
然后是我们必须保存的IP地址(匹配项中的最后一个IP是将存储IP地址的变量的名称): {IP,%{IPV4:IP}
{JTX,1511059/176275501}{OBJT,goodsMovement.reportsUtils.ConsignmentStocksList}{OPT,SQ}
. {JTX,1511059/176275501}{OBJT,goodsMovement.reportsUtils.ConsignmentStocksList}{OPT,SQ}
。 For grok it looks like: ({.*}){3}
; ({.*}){3}
; {PID,111111}
. {PID,111111}
。 For grok PID is just a positive integer similarly to IP surrounded by curly brackets and with PID,
in front: {PID,%{POSINT:PID}}
; PID,
包围) PID,
位于前面: {PID,%{POSINT:PID}}
; ({.*}){2}
; ({.*}){2}
; {UID,StudentSaSo-8}
, which is just a string of data for grok. {UID,StudentSaSo-8}
,这只是grok的数据字符串。 Similarly to IP and PID saving it in the respective variable: {UID,%{DATA:UID}}
; {UID,%{DATA:UID}}
; }
. }
。 In the end your final grok will look as follows: 最后,您的最终傻瓜如下所示:
(?<timestamp>%{YEAR}-%{MONTHNUM}-%{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND},%{NONNEGINT})\] %{LOGLEVEL:loglevel} * \[(?<logger>[A-Za-z0-9$_.]+)\] \(%{JAVAFILE:class}:%{NONNEGINT:line}\) \[%{NOTSPACE:thread}\] {%{DATA}{IP,%{IPV4:IP}}({.*}){3}{PID,%{POSINT:PID}}({.*}){2}{UID,%{DATA:UID}}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.