Under one index I have multiple log files and one of those log file will use a different grok format than the other three log files. How can I apply grok pattern based on if statement on file name? For example,
This is a block of my filebeat.yml. I want that under index "obapp-dotnet", log.tct and exceptionlog.txt use one grok pattern and dispatcher.log uses another type of grok pattern.
So,
if {dispatcher.log} use pattern1
else {exceptionlog.txt} use pattern 2
@mancharagopan will this line be helpful in creating path as a field and then apply if statement on path since it will have file name such as dispatcher?
Although I tried this line and it doesnt create "path" as field. I would expect this line would create a field called Path: dispatcher.log. Or any other suggestion how I could have filename extracted in grok?
filebeat.inputs:
# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.
- type: log
# Change to true to enable this input configuration.
enabled: true
input_type: log
fields:
tags: ["obapp-dotnet"]
# Paths that should be crawled and fetched. Glob based paths.
paths:
- 'C:\Program Files (x86)\ESQ SST\Logs\OBWebAPI\log.txt'
- 'C:\Program Files (x86)\ESQ SST\Logs\OBWebAPI\exceptionlog.txt'
- 'C:\Program Files (x86)\ESQ SST\Logs\IMSService\log.txt'
- 'C:\Program Files (x86)\ESQ SST\Logs\IMSService\exceptionlog.txt'
- type: log
enabled: true
input_type: log
fields:
tags: ["obapp-java"]
# Paths that should be crawled and fetched. Glob based paths.
paths:
- 'C:\Program Files (x86)\ESQ SST\DispatcherApp\logs\*.log'
- 'C:\Program Files (x86)\ESQ SST\RBACService\logs\*.log'
- 'C:\Program Files (x86)\ESQ SST\OBAPI\logs\*.log'
this is block of filebeat.yml. The two tags get created as seperate indexes.
filter {
if[fields][log_type] =="obapp-java" {
grok {
#breaks if first match good, hence false to consider second match too.
break_on_match => false
match => {
"message" => [\A%{TIMESTAMP_ISO8601:timestamp}%{SPACE}%{GREEDYDATA}%{SPACE}%{LOGLEVEL:logLevel}%{SPACE}%{GREEDYDATA}%{SPACE}%{JAVACLASS:javaClass}
]
}
}
filter {
grok {
match => ["path","%{GREEDYDATA}/%{GREEDYDATA:filename}\.log"]
}
}
}
else if [fields][log_type] == "obapp-dotnet" {
grok {
break_on_match => false
match => ["path","%{GREEDYDATA}/%{GREEDYDATA:filename}\.log"]
if [path] = "dispatcher.log" {
grok{
match => {
"message" => [ ]
}
}
else {
match => {
"message" => [\A%{TIMESTAMP_ISO8601:timestamp}%{SPACE}%{GREEDYDATA}%{SPACE}%{LOGLEVEL:logLevel}%{SPACE}%{GREEDYDATA}%{SPACE}%{JAVACLASS:javaClass}
]
}
}
}
}
}
}
````onapp-dotnet````
'C:\Program Files (x86)\ESQ SST\Logs\OBWebAPI\log.txt
27/01/2020 00:04:56 (null) INFO 10 OB.WebAPI.Business.Logic.OBWebAPIManager..ctor Entry Time - 27-01-2020 00:04:56.172
'C:\Program Files (x86)\ESQ SST\Logs\OBWebAPI\exceptionlog.txt' - \A%{TIMESTAMP_ISO8601:timestamp}%{SPACE}%{GREEDYDATA}%{SPACE}%{LOGLEVEL:logLevel}%{SPACE}%{GREEDYDATA}%{SPACE}%{JAVACLASS:javaClass}
2020-01-02 15:19:40,710: (null) ERROR: (ESQ.CrossCutting.Instrumentation.ExceptionLoggingAspectAttribute.OnException(),Ln 0): OB.WebAPI.OBWebAPI.OB.WebAPI.Contracts.v1.IMS.GetIncidentArray failed. Message:Value cannot be null.
````onapp-java````
'C:\Program Files (x86)\ESQ SST\DispatcherApp\logs\dispatcher.log
2020-01-27 03:11:21,038 [DispatcherScheduler_Worker-2] INFO o.a.c.h.HttpMethodDirector - Retrying request
'C:\Program Files (x86)\ESQ SST\RBACService\logs\rbac.log
2020-01-27 00:21:23,337 INFO [qtp2141445292-70219] org.eclipse.jetty.server.session - Session node0mppnjr4chzg1eps3zohnru4217853 already being invalidated
C:\Program Files (x86)\ESQ SST\OBAPI\logs\*.log
20191203 04:50:54.671 [main] INFO o.s.b.f.x.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [config/obapi-custom-data-config.xml]
Under first index are two file paths mentioned with a sample of log type stored in them. So with index onapp-dotnet, file path is "c:....log.txt' and the format of log in it is in next line.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.