Splunk Search

How to use a column of data in a CSV lookup to initiate a search?

joea9
Explorer

I am using a CSV lookup that adds additional fields to my Splunk search results...

Search string:

date_month=october OR date_month=june | lookup mylookup month as date_month

CSV file:

month,shortname
july,jul
june,jun
october,oct

So it's matching the date_month field in my search results with the month column in my CSV file and returning the 'shortname' as a new field.

QUESTION

However, I want to use data in my CSV file to initiate the search instead. I want to do a lookup that will return all of the months in the month column of my CSV file, and then do a search on them, while including the additional 'shortname' field in the search results?

I got this far:

| inputlookup myiplookup | fields month

Which returns the list of values in my CSV 'month' column, but it doesn't actually search on them, and doesn't return the 'shortname' field.

Tags (4)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Searching based on lookup fields and adding fields to results from a lookup are two separate things, so you will need to do two steps to achieve this.

First, configure your lookup as an automatic lookup on your data. That'll allow you to leave off the explicitly | lookup command from your first search.
Second, run a search like this:

index=foo sourcetype=bar [inputlookup mylookup | fields month | rename month as date_month] | ...

That'll build an OR'd list of date_month filters from your lookup.

As an alternative, having the automatic lookup also allows you to write this kind of search:

index=foo sourcetype=bar shortname=jun | ...

That will be translated to date_month=june under the hood.

Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...