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!

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