Splunk Search

grouping events based on start and end

venky1544
Builder

Hi All

i have a below data 

DateOrginaldatejobidprocess_nameMessge_text
14-02-2020 T11:30:0014-02-2020 T11:25:00a1234testprocess1process start
14-02-2020 T11:45:0014-02-2020 T11:35:00a1236testprocess2process start
14-02-2020 T12:00:0014-02-2020 T11:47:00a1234testprocess1process ends
14-02-2020 T12:15:0014-02-2020 T11:50:00a1235testprocess3process start
14-02-2020 T12:30:0014-02-2020 T12:17:00a1235testprocess3process ends
14-02-2020 T12:45:0014-02-2020 T12:35:00a1236testprocess2process ends
14-02-2020 T13:00:0014-02-2020 T12:50:00a1237testprocess4process start
14-02-2020 T13:15:0014-02-2020 T13:05:00a1237testprocess4process ends

 

i want to group the events jobid  based on original date column and not the _time or the first column  and want the below output 

Orginaldatejobidprocessnamestart msgend_msgduration
14-02-2020 T11:25:00a1234testprocess1process startprocess ends1320
14-02-2020 T11:35:00a1236testprocess2process startprocess ends3600
14-02-2020 T11:50:00a1235testprocess3process startprocess ends1620
14-02-2020 T12:50:00a1237testprocess4process startprocess ends900

 

i have tried the timestamp into epoch and then grouped the event but im not able separate out the two start and endtime

Labels (1)
0 Karma
1 Solution

vikas_gopal
Builder

One way is with transaction 

 

sourcetype="csv" |transaction jobid startswith=eval(Messge_text="processstart") endswith=eval(Messge_text="processends") |eval duration= tostring(duration,"duration") |table Orginaldate,jobid,Messge_text,duration

Because we know transaction command is a little expansive command so we can use fields as well to only focus on respective fields

sourcetype="csv" |fields Orginaldate,jobid,Messge_text|transaction jobid startswith=eval(Messge_text="processstart") endswith=eval(Messge_text="processends") |eval duration= tostring(duration,"duration") |table Orginaldate,jobid,Messge_text,duration

 

In case you are extracting message from a fields as a new field then you can use below 

sourcetype="csv" |rex field=Messge_text "(?<actual_message>processstart)" |rex field=Messge_text "(?<actual_message>processends)"|transaction jobid |eval duration= tostring(duration,"duration") |sort Orginaldate|table Orginaldate,actual_message,jobid,duration

View solution in original post

0 Karma

venky1544
Builder

Hi Vikas 

I tried the above commands and it didn't worked for me but i tweaked the solution by shuffling the rex extractions at the end and it worked for me not sure if its a right approach below is my modified query 

sourcetype="csv"|transaction jobid startswith=eval(Messge_text="process start") endswith=eval(Messge_text="process ends") |eval duration= tostring(duration,"duration") |rex field=Messge_text "(?<start_message>process start)" |rex field=Messge_text "(?<end_message>process ends)"|table Orginaldate,jobid,start_message,end_message,duration

0 Karma

vikas_gopal
Builder

One way is with transaction 

 

sourcetype="csv" |transaction jobid startswith=eval(Messge_text="processstart") endswith=eval(Messge_text="processends") |eval duration= tostring(duration,"duration") |table Orginaldate,jobid,Messge_text,duration

Because we know transaction command is a little expansive command so we can use fields as well to only focus on respective fields

sourcetype="csv" |fields Orginaldate,jobid,Messge_text|transaction jobid startswith=eval(Messge_text="processstart") endswith=eval(Messge_text="processends") |eval duration= tostring(duration,"duration") |table Orginaldate,jobid,Messge_text,duration

 

In case you are extracting message from a fields as a new field then you can use below 

sourcetype="csv" |rex field=Messge_text "(?<actual_message>processstart)" |rex field=Messge_text "(?<actual_message>processends)"|transaction jobid |eval duration= tostring(duration,"duration") |sort Orginaldate|table Orginaldate,actual_message,jobid,duration

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...