Hi @mvagionakis,
Here is my thought on a solution:
| makeresults
| eval testdata="^26/02/2020 16:34:21|toto|test|600|440|Session End|device=titi|sessionId=3bee772f147|ext=External^26/02/2020 16:34:21|toto|test|600|440|Upload|sessionId=3bee772f147|ext=External|username=mvag^"
| rex field=testdata max_match=0 "\^(?<events>[^\^]+)"
| table testdata events
| fields - testdata
| mvexpand events
| rename events AS _raw
| rex field=_raw "^(?<timestamp>[^\|]+)\|"
| eval _time=strptime(timestamp, "%d/%m/%Y %H:%M:%S")
| rex field=_raw "device=(?<device>\w+)\|"
| rex field=_raw "sessionId=(?<sessionId>\w+)\|"
| rex field=_raw "ext=(?<ext>\w+)"
| rex field=_raw "([^\|]+\|){5}(?<action>[^\|]+)\|"
| rex field=_raw "username=(?<username>\w+)"
| eval starttime=if(action="Upload", _time, null)
| eval endtime=if(action="Session End", _time, null)
| stats values(username) min(starttime) AS starttime max(endtime) AS endtime by sessionId
| eval sessionlength=endtime-starttime
Explaination:
| makeresults
| eval testdata="^26/02/2020 16:34:21|toto|test|600|440|Session End|device=titi|sessionId=3bee772f147|ext=External^26/02/2020 16:34:21|toto|test|600|440|Upload|sessionId=3bee772f147|ext=External|username=mvag^"
| rex field=testdata max_match=0 "\^(?<events>[^\^]+)"
| table testdata events
| fields - testdata
| mvexpand events
| rename events AS _raw
| rex field=_raw "^(?<timestamp>[^\|]+)\|"
| eval _time=strptime(timestamp, "%d/%m/%Y %H:%M:%S")
| rex field=_raw "device=(?<device>\w+)\|"
| rex field=_raw "sessionId=(?<sessionId>\w+)\|"
| rex field=_raw "ext=(?<ext>\w+)"
| rex field=_raw "([^\|]+\|){5}(?<action>[^\|]+)\|"
| rex field=_raw "username=(?<username>\w+)"
Everything up to this point is to create my run anywhere test data for your test case. In all likelihood, depending on how your sourcetype was created, you will not need to extract some of the fields (any with fieldname=fieldvalue should be extracted by themselves... I created the field "action" to get the "Session End" / "Upload" values
| eval starttime=if(action="Upload", _time, null)
| eval endtime=if(action="Session End", _time, null)
This bit creates a field called starttime, for all the events where action=Upload (if you have more than one possible action that can signify the start of the transaction, this may need to be more detailed, either with a nested if, or a case)
| stats values(username) min(starttime) AS starttime max(endtime) AS endtime by sessionId
Here we group each sessionId by its starttime endtime and username combinations
| eval sessionlength=endtime-starttime
Lastly, i am using the difference between the start and end to set a duration.
Let me know if this helps. .
./Darren
... View more