Splunk Search
Highlighted

Search result as input to another search

Communicator

Hi, anybody has an idea on how to get a value from one search and input it to another search, then display them in a table? Sample below.

I’ll search for IP_Address on 1st search, then take that into 2nd search and find the Hostnames of those ip address…then display them

Search1:

sourcetype=srctype1 OR sourcetyp=srctype2 dstIP=1.1.1.1 OR dstIP=2.2.2.2|fields + srcIP dstIP|stats count by srcIP

Search2:

sourcetype=srctype3 (input srcIP from Search1)|fields + Hostname|stats count by srcIP Hostname

Display Table:

srcIP__________Hostname

a.b.c.d_______________abcd

Tags (2)
Highlighted

Re: Search result as input to another search

Legend

This is exactly what subsearches were made for. Have a look at the docs that cover this: http://docs.splunk.com/Documentation/Splunk/latest/User/HowSubsearchesWork

View solution in original post

Highlighted

Re: Search result as input to another search

Communicator

just trying to get back on old questions....subsearch is definitely the way to go but not efficient for multiple subsearch results.

0 Karma
Highlighted

Re: Search result as input to another search

New Member

The link in the Accepted Answer link text seems to no longer reach an answer to this question because of update to SPLUNK. When I try it I get page that says:

Hi! Just wanted to let you know:

The topic you've asked to see does not apply to the most recent version.

To search the latest version of the documentation, click Search

0 Karma
Highlighted

Re: Search result as input to another search

Explorer

I'm not sure if I understood your question, but you should try something like :

sourcetype=srctype3 | join [ search sourcetype=srctype1 OR sourcetyp=srctype2 dstIP=1.1.1.1 OR dstIP=2.2.2.2 | fields + srcIP dstIP | stats count by srcIP ] | fields + Hostname | stats count by srcIP Hostname

And see what you get. Let me know if it helps you.

Highlighted

Re: Search result as input to another search

Communicator

This is really an old post, but I'm still looking for a way here. The join doesn't seem to resolve this as it mixes the results.

Just to be exact, I want to match an IP address from a proxy log to a device name or username from AD logs since there is no device name in the proxy logs. I want to input the IP address seen in proxy logs to the AD logs search for device name.

0 Karma
Highlighted

Re: Search result as input to another search

Communicator

As Ayn said, subsearch is what you want. Perform a subsearch for the proxy event then feed that into a search through ad logs. It should look something like:

sourcetype=adlogs [search sourcetype=proxylogs | fields ipaddress] | table user ipaddress

Keep in mind the above assumes your proxy logs have the ip address in a fields called ipaddress, and your ad logs have the username and ip address in fields user and ipaddress respectively

0 Karma
Highlighted

Re: Search result as input to another search

Communicator

I did try the subsearch, however i kept running into the error "Error in 'fields' command: Invalid argument: 'fieldname=field_value'.

Then I ran into one of the Answers on another post, saying I Should add "|rename field as query". This one doesn't go into errors but doesn't get results either.

I'm looking into a document about creating State Tables.

Thanks.

0 Karma
Highlighted

Re: Search result as input to another search

Legend

Uh, wouldn't be better to put your energy into troubleshooting your syntax problems with the probably best approach to solving your problems, rather than trying something else just because you couldn't get it right?

Highlighted

Re: Search result as input to another search

Communicator

When you get errors like that, you should read the search command reference for that command. Specifically, with regards to the fields command, you're not using it properly.

Fields command synopsis: Keeps or removes fields from search results.

0 Karma