Splunk Search

macro with 2 arguments and a where clause

smolcj
Builder

hi,
i have a search query like

index=main a=* OR b=* 'macroname("a","b")' |table b b1 b2 b3

my macro is like

macroname(2)

def: sourcetype=log |where $a$=$b$
args a,b

i used splunk web to create this macro
what i want is, a and b are in diferent events and i want to display all the common values in a and b in a table with some other values present in the same event as b.
i tried to figure it out by myself. i am sorry if i missed any documents helping this
can lookup do this job?
i refered to this answer here
please help
Thank you

Tags (2)
1 Solution

jonuwz
Influencer

Macros wont help you here.

index=main [ search index=main a=* OR b=* | stats count by a b | where a>0 AND b>0 | fields b ] | table b b1 b2 b3

What does the bit in square brackets do ?

run this :

index=main a=* OR b=* | stats count by a b | where a>0 and b>0 | fields b | format

This is substituted into the main search.

So the main search becomes

index=main (( b=something) OR ( b=somethingelse) OR ( .. )) | table b b1 b2 b3

View solution in original post

0 Karma

jonuwz
Influencer

Macros wont help you here.

index=main [ search index=main a=* OR b=* | stats count by a b | where a>0 AND b>0 | fields b ] | table b b1 b2 b3

What does the bit in square brackets do ?

run this :

index=main a=* OR b=* | stats count by a b | where a>0 and b>0 | fields b | format

This is substituted into the main search.

So the main search becomes

index=main (( b=something) OR ( b=somethingelse) OR ( .. )) | table b b1 b2 b3
0 Karma

smolcj
Builder

thanks jonuwz. a and b is in separate events and a is extracted in transforms.conf.
now i found that this query is working fine for me.
index=main sourcetype=log source=SUCCESS a=* OR b=* | eval b=coalesce(a, b) | stats dc(a) as occur by b|where occur>0 |fields b| join b[ search source=SUCCESS | fields b b1 b2 b3 b4 ] |table b b1 b2 b3 b4

Thank you for tour time

0 Karma

jonuwz
Influencer

are fields a and b in the same event ?

Can you post sample data and the required output

0 Karma

smolcj
Builder

thanks jonuwz, but the above search is not working for me, as i mentioned in my question , i have to compare two different field values, | where $a$=$b$ and select those values from b and display.
| stats count by a b | where a>0 and b>0
is not giving any result
Thank you

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...