Dashboards & Visualizations

Could someone help me with Regex to extract suitable fields?

sphiwee
Contributor

I have the below log and I'm using the following regex to extract these fields "date", "process" ,"step", "user", "log level" 

rex "^(?<Date>\d+-\d+-\d+\s+\d+:\d+:\d+)\s+\[[^\]]*\]\s+\[(?<Process>\[[^\]]+\][^\]]+)\]\s+\[(?<Step>[^\]]+)\]\s+\[(?<User>[^\]]+)\]\s+[^\[]+\[(?<Log_level>[^\]]+)


When the log is like the first entry data is extracted without an issue, but once it's like the last three entries nothing is extracted, how can I solve this. 

2021-09-28 10:20:27 [machine-run-76416-hit-644640-step-12470][Business Process Name][Business Process Step Name][Bot Users] MetadataStorage [ERROR] Boot failed

2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] DataBaseChecker [DEBUG] Checking MySQL ...
2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] DatabaseVersionChecker [INFO] Database is up to date.
2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] DataBaseChecker [DEBUG] Checking PostgreSQL ...
2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] OcrHealthChecker [DEBUG] Checking OCR ...


Labels (3)
Tags (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Your log messages don't quite tally with the regex you say works (as @gcusello ) pointed out. If the spaces are supposed to be absent, try this

^(?<Date>\d+-\d+-\d+\s+\d+:\d+:\d+)\s+\[[^\]]*\]\s*\[(?<Process>[^\]]*)\]\s*\[(?<Step>[^\]]*)\]\s*\[(?<User>[^\]]*)\]\s*[^\[]+\s\[(?<Log_level>[^\]]+)

https://regex101.com/r/WvRDp5/1 

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Your log messages don't quite tally with the regex you say works (as @gcusello ) pointed out. If the spaces are supposed to be absent, try this

^(?<Date>\d+-\d+-\d+\s+\d+:\d+:\d+)\s+\[[^\]]*\]\s*\[(?<Process>[^\]]*)\]\s*\[(?<Step>[^\]]*)\]\s*\[(?<User>[^\]]*)\]\s*[^\[]+\s\[(?<Log_level>[^\]]+)

https://regex101.com/r/WvRDp5/1 

sphiwee
Contributor

Thanks this works, how can I also extract the words after the error? So i can identify the error that I received

Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
^(?<Date>\d+-\d+-\d+\s+\d+:\d+:\d+)\s+\[[^\]]*\]\s*\[(?<Process>[^\]]*)\]\s*\[(?<Step>[^\]]*)\]\s*\[(?<User>[^\]]*)\]\s*[^\[]+\s\[(?<Log_level>[^\]]+)\]\s*(?<Error>.+)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @sphiwee,

please check this regex:

| rex "^(?<timestamp>\d+-\d+-\d+\s+\d+:\d+:\d+)\s+\[[^\]]*\]\s+\[(?<business_process_name>[^\]]*)\]\s+\[(?<business_process_step>[^\]]*)\]\s+\[(?<users>[^\]]*)\]\s+\w+\s+\[(?<error>[^\]]*)\]"

that you can test at https://regex101.com/r/NuLFWU/1

put attention to this point: you have some missing space in the first row.

Ciao.

Giuseppe

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...