Splunk Search

Pass search results to another search

ulankford
Engager

I have the following search

index=linux_syslog netgroup=my_servers* user@email.com | rex field=_raw "sendmail\[\d+\]: (?<SendmailMessageID>\w+): "  

Now I can do things like top and the like to display the unique sendmailID that I have extracted from the logs that the user@email.com sends.
However, I want to use the SednmailMessageID that I have extracted and search again using other data that is found in logs.

e.g.
SendmailMessageID 'accepted for delivery'

So can I combine these two searches into the one?
Should I be looking at sub searches or even transactions?

Tags (3)
0 Karma

ulankford
Engager

Thanks for that. I understand the logic behind this now, but the search returns nothing so far.
When you say that you have a SendmailMessageID created via a rex command, do you need to create this again in the outer search? As to my mind this is the 'variable' to put it that we want to use in the outer search. it seems to me that we are just defining it again, instead of passing the value of it from the inner search to the outer search.

The inner search on its own will return over 1000 unique values, which I then want to use to do an additional search for each.

index=linux_syslog netgroup=my_servers* "succesfull delivery"  [search index=linux_syslog netgroup=my_servers* my@emailaddress.com| rex field=_raw "sendmail\[\d+\]: (?<SendmailMessageID>\w+):" | stats count by SendmailMessageID]   |  rex field=_raw "sendmail\[\d+\]: (?<SendmailMessageID>\w+):" 

As an aside what is authenticationtype used for?

0 Karma

masonmorales
Influencer

Yes, you would use a subsearch if you wanted to use the results from one search as search criteria in another search. Subsearches are created by putting the first search you want executed in brackets with a search command in front. They are treated as a boolean AND to your outer search. One thing to note is that you do need to have matching field names between the outer and inner search for it to work properly. Here's a mock-up of how you might do it:

index=linux_audit authenticationtype=*  [search index=linux_syslog netgroup=my_servers* user@email.com | rex field=_raw "sendmail\[\d+\]: (?<SendmailMessageID>\w+):" | stats count by SendmailMessageID]   |  rex field=_raw "sendmail\[\d+\]: (?<SendmailMessageID>\w+):" | stats count by sendmailID, authenticationtype, etc

See also: http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchTutorial/Useasubsearch

In my example I used the rex command to create the SendmailMessageID because you have to have similar field value contents in both sources. You may have to rex some other field, do a rename, or tweak your original extraction to get matching field values (i.e. you must have user=bob in one search, and user=bob in your other search for it to work).

You could also try adding a join command to the end of your first search. The same principle of having matching field names/similar values applies to join as wel. See: http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/Join

0 Karma
Get Updates on the Splunk Community!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...