Splunk Search

Group events by a field and fetch those ones where a second field does not match a given value

ariel123
Engager

I have these events with CID which normally come as a pair of TranType Request and Response.
2017-12-04 09:45:01 CID=111 TranType=Response
2017-12-04 09:44:01 CID=111 TranType=Request
2017-12-04 09:42:01 CID=222 TranType=Request
2017-12-04 09:41:01 CID=333 TranType=Response
2017-12-04 09:39:01 CID=333 TranType=Request
2017-12-04 09:37:01 CID=444 TranType=Request

All I need is to display all the CID that are missing the corresponding TranType of Response such that the above will show as:
CID 222
CID 444

Appreciate your advice on this. Thanks!

0 Karma
1 Solution

renjith_nair
Legend

@ariel123

Try

        <your index search> |stats count by CID|where count > 1
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

ariel123
Engager

Hi renjith,
Thanks. This gives me a great hint on how to go about it.

Much appreciated!

0 Karma

renjith_nair
Legend

@ariel123

Try

        <your index search> |stats count by CID|where count > 1
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

harsmarvania57
Ultra Champion

Hi @ariel123,

Based on sample data I have created 2 different queries. Can you please try both the queries ? First 6 lines are for sample data only.

| makeresults
| eval raw="2017-12-04 09:45:01 CID=111 TranType=Response:::2017-12-04 09:44:01 CID=111 TranType=Request:::2017-12-04 09:42:01 CID=222 TranType=Request:::2017-12-04 09:41:01 CID=333 TranType=Response:::2017-12-04 09:39:01 CID=333 TranType=Request:::2017-12-04 09:37:01 CID=444 TranType=Request"
| makemv delim=":::" raw
| mvexpand raw
| rename raw AS _raw
| rex "CID=(?<CID>\d+)\sTranType=(?<TranType>\w+)"
| transaction CID
| mvcombine TranType
| eval Result=if(TranType="Request Response",1,0)
| where Result=0

Second query using stats command

| makeresults
| eval raw="2017-12-04 09:45:01 CID=111 TranType=Response:::2017-12-04 09:44:01 CID=111 TranType=Request:::2017-12-04 09:42:01 CID=222 TranType=Request:::2017-12-04 09:41:01 CID=333 TranType=Response:::2017-12-04 09:39:01 CID=333 TranType=Request:::2017-12-04 09:37:01 CID=444 TranType=Request"
| makemv delim=":::" raw
| mvexpand raw
| rename raw AS _raw
| rex "CID=(?<CID>\d+)\sTranType=(?<TranType>\w+)"
| stats values(TranType) AS TranType by CID
| mvcombine TranType
| eval Result=if(TranType="Request Response",1,0)
| where Result=0
0 Karma

ariel123
Engager

Hi harsmarvania57,
Thanks for your reply. I never thought it would be a bit this complicated though 🙂 Is there any other way of accomplishing it without having to rely on delimiters specially the CID and TranType fields are available?

Cheers

0 Karma

harsmarvania57
Ultra Champion

Hi @ariel123,

As I mentioned earlier first 6 lines are used to generate sample data to create a query in my environment. So to simplify, your query will be

Using transaction

<your search> | transaction CID
 | mvcombine TranType
 | eval Result=if(TranType="Request Response",1,0)
 | where Result=0

Using stats

<your search> | stats values(TranType) AS TranType by CID
 | mvcombine TranType
 | eval Result=if(TranType="Request Response",1,0)
 | where Result=0

I prefer second one because transfroms will use more resources.

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...

[Puzzles] Solve, Learn, Repeat: Dereferencing XML to Fixed-length events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...