Splunk Search

Help with Splunk Regex

kc_prane
Communicator

Hi Team -  Need your expertise in Regex.

The below is the rawlog i need to extract the Date and time  the only unique is the WORD "START" & "END" goal is to find the response time between START and END in a Table format.

Note: there are no space in the log

START</enteringExiting><logLevel>INFO</logLevel><messageType>LOG</messageType><applicationName>GstarSOA</applicationName<programName>GstarRecipientService_MF</programName><functionName>GetRecipient</functionName><host>PerfNode0</host><messageDetails>2022-06-17 04:10:53/utility/logging"><enteringExiting>END</enteringExiting><logLevel>INFO</logLevel><messageType>LOG</messageType><applicationName>GstarSOA</applicationName><programName>GstarRecipientService_MF</programName<functionName>GetRecipient</functionName><host>PerfNode0</host><messageDetails>2022-06-17 04:10:53
Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

HI @kc_prane,

if the shared sample is in one event, you could use the following regex:

| rex "START.*messageDetails\>(?<Start_Date>\d+-\d+-\d+\s+\d+:\d+:\d+)\/.*END.*messageDetails\>(?<End_ate>\d+-\d+-\d+\s+\d+:\d+:\d+)"

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

If instead you have two events, you can separate the above regex in two regexes.

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

HI @kc_prane,

if the shared sample is in one event, you could use the following regex:

| rex "START.*messageDetails\>(?<Start_Date>\d+-\d+-\d+\s+\d+:\d+:\d+)\/.*END.*messageDetails\>(?<End_ate>\d+-\d+-\d+\s+\d+:\d+:\d+)"

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

If instead you have two events, you can separate the above regex in two regexes.

Ciao.

Giuseppe

0 Karma

kc_prane
Communicator

Thanks Gcusello !

i modifed your solutiion it worked.

| rex "START.*messageDetails\>(?<Start_Date>\d+\-\d+\-\d+\s+\d+\:\d+\:\d+)" | rex "END.*messageDetails\>(?<End_Date>\d+\-\d+\-\d+\s+\d+\:\d+\:\d+)"

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @kc_prane,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

kc_prane
Communicator

Hi @gcucello

Can you also help me how to seperate the date and time in the regex. Cause i wanted to find the difference between Start_time and End_time

 

| rex "START.*messageDetails\>(?<Start_Date>\d+\-\d+\-\d+\s+\d+\:\d+\:\d+)"

My results : 2022-06-17 03:49:46

                            

 

 

0 Karma

kc_prane
Communicator

Hi @gcucello -  No worries I got the solution, thanks a lot

| rex "START.*messageDetails\>\d+\-\d+\-\d+\s+(?<Start_Time>\d+\:\d+\:\d+)" | rex "END.*messageDetails\>\d+\-\d+\-\d+\s+(?<End_Time>\d+\:\d+\:\d+)"
| eval ST = Strptime(Start_Time, "%H:%M:%S.%3N")
| eval ET = Strptime(End_Time, "%H:%M:%S.%3N")
| eval ResponseTime = tostring((ET -ST), "duration")
| table _time host tag::host Start_Time End_Time ResponseTime

0 Karma

marysan
Communicator

@kc_prane 
Hi

Would you give me an example of your expected result ?
how do you calculate response time between start and end ? with messageDetails?

0 Karma

kc_prane
Communicator

Hi Marysan - Thanks for the reply, i got the solution

 

| rex "START.*messageDetails\>\d+\-\d+\-\d+\s+(?<Start_Time>\d+\:\d+\:\d+)" | rex "END.*messageDetails\>\d+\-\d+\-\d+\s+(?<End_Time>\d+\:\d+\:\d+)"
| eval ST = Strptime(Start_Time, "%H:%M:%S.%3N")
| eval ET = Strptime(End_Time, "%H:%M:%S.%3N")
| eval ResponseTime = tostring((ET -ST), "duration")
| table _time host tag::host Start_Time End_Time ResponseTime

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...