Splunk Search

Subsearch to only return multiple field values

SailorManDan
Explorer

Hello,

 

I am trying to only return the values of certain fields to be used in a subsearch. The problem I'm encountering, is that I have multiple values from different fields which I want to extract.

I have 4 fields - src, src_port, dst, dst_port

If I table out the results and use format, my search reads as such:

"src"="<IP>" AND "src_port"="<port>" AND "dst"="<IP>" AND "dst_port"="<port>" 

What I want is only the values:

"<ip>" AND "<port>" AND "<ip>" AND "<port>"

I've tried using:
return 10 $src $src_port $dst $dst_port
which gives me the desired output, but encases the entire output in one set of quotations and not individually as per the same output that would be created using the table command

I've also tried using:

eval query = src. " " .src_port. " " .dst. " " .dst_port 

which gets me closer, but then outputs each four values encased within the quotations.

 

Can anyone help me out with the desired output?

 

Regards,

Dan

 

 

 

 

 

 

Labels (2)
1 Solution

dwaddle
SplunkTrust
SplunkTrust

The "query" field is special.  Any field named "query" gets its field name stripped going through format.  Try something like this:

|  makeresults 
|  eval src_ip="1.2.3.4", src_port=1234, dest_ip="5.6.7.8", dest_port=5678 
|  eval query=mvappend(src_ip,src_port,dest_ip,dest_port) 
|  fields query
|  format mvsep="AND"

 

The last 3 lines are the relevant part, makeresults is just there to help me mock up some stuff.

View solution in original post

dwaddle
SplunkTrust
SplunkTrust

groovy! please accept as solution?

0 Karma

dwaddle
SplunkTrust
SplunkTrust

The "query" field is special.  Any field named "query" gets its field name stripped going through format.  Try something like this:

|  makeresults 
|  eval src_ip="1.2.3.4", src_port=1234, dest_ip="5.6.7.8", dest_port=5678 
|  eval query=mvappend(src_ip,src_port,dest_ip,dest_port) 
|  fields query
|  format mvsep="AND"

 

The last 3 lines are the relevant part, makeresults is just there to help me mock up some stuff.

View solution in original post

SailorManDan
Explorer

@dwaddle 

That's got it!

This is precisely what I was going for. 

Thanks for you help.

0 Karma
Did you miss .conf21 Virtual?

Good news! The event's keynotes and many of its breakout sessions are now available online, and still totally FREE!