Splunk Search

difference of two values of same field inside a transcation

KarunK
Contributor

Hi ALL,

I am using a transaction command to group two events together, "connect" and "disconnect". Both the events have a common field called bytes and I need to get the difference of the bytes delivered during the disconnect event and connect event.

How can I achieve this ?

(sourcetype="access" event="*connect" status="200") | transaction c_ip eventttype startswith="connect" endswith="disconnect"

Thanks in Advance

Aappreciate your help.

Tags (1)
0 Karma
1 Solution

Ayn
Legend

Use mvlist=t as a parameter to transaction to make sure you're getting field values in the correct (chronological) order, then use mvindex to get the first and last value for bytes.

... | transaction mvlist=t c_ip eventtype startswith="connect" endswith="disconnect" | eval bytesdiff=tonumber(mvindex(bytes,-1))-tonumber(mvindex(bytes,0))

View solution in original post

Ayn
Legend

Use mvlist=t as a parameter to transaction to make sure you're getting field values in the correct (chronological) order, then use mvindex to get the first and last value for bytes.

... | transaction mvlist=t c_ip eventtype startswith="connect" endswith="disconnect" | eval bytesdiff=tonumber(mvindex(bytes,-1))-tonumber(mvindex(bytes,0))

KarunK
Contributor

Thanks Ayn. It worked....

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...