Splunk Search

CSV Lookup for search query

keyu921
Explorer

I prepared csv to inputlookup to compare the Splunk logs.

adhoc.csv

//

Account,

test01,etc....

test02,etc....

//

my Query

index=msad sourcetype=msad [| inputlookup adhoc.csv | fields Account] 
Searching Period: Last 24 hours

Cross check adhoc.csv match the searching logs.

For those account did not perform any authentation which logs stored at index=msad, during search period, then show zero values.

 

0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @keyu921,

please try this:

index=msad sourcetype=msad 
| eval Account=lower(Account)
| stats count BY Account
| append [| inputlookup adhoc.csv | eval Account=lower(Account), count=0 | fields Account count] 
| stats sum(count) AS total BY Account
| where total=0

In this way,

  • total>o means that there are logs,
  • total=0 means that there aren't logs.

As you requested, I added at the end a filter to display only the ones without logs, but you could also create a dashboard displaying all the Accounts with their status.

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @keyu921,

please try this:

index=msad sourcetype=msad 
| eval Account=lower(Account)
| stats count BY Account
| append [| inputlookup adhoc.csv | eval Account=lower(Account), count=0 | fields Account count] 
| stats sum(count) AS total BY Account
| where total=0

In this way,

  • total>o means that there are logs,
  • total=0 means that there aren't logs.

As you requested, I added at the end a filter to display only the ones without logs, but you could also create a dashboard displaying all the Accounts with their status.

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

hi @keyu921,

good for you.

Ciao and happy splunking.

Giuseppe

P.S.: Karma Points are appreciated 😉

bowesmana
SplunkTrust
SplunkTrust

This will show you all the Account names from the CSV that did NOT have any entries in the msad log in the time period given. It first searches and counts all the data for the monitored accounts, then adds back all the accounts being monitored and just then looks for ones with no count value.

index=msad sourcetype=msad [| inputlookup adhoc.csv | fields Account] 
| stats count by Account
| append [
  | inputlookup adhoc.csv | fields Account
]
| stats values(count) as count by Account 
| where isnull(count)

Hope this helps

  

0 Karma

yeahnah
Motivator

Hi @keyu921 

It's not overly clear what you are asking for so I not going to try, however if you want to have an OR statement generated for you base search, from the adhoc.csv file, then you need to use the format command, as shown

 

... your search ... [| inputlookup adhoc.csv | fields Account | format] | ...

 

Substituted result of the subsearch would be

 

 ... your search ... ( ( Account="test1" ) OR ( Account="test2" ) ) | ...

 

 
Having said that, more often than not, the use of the lookup command is far more efficient ...

 

... your search ...
| lookup adhoc.csv Account AS Account OUTPUTNEW <...some new field in adhoc.csv...>
| where isnotnull(<some new field>) 

 

Check the Splunk docs for more details, if interested.

Hope this helps

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...