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!

.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 ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...