Splunk Search

search using Inputlookup with wildcard field - unable to retain wildcard key in result

rahul0621
Explorer

I am using inputlookup in a search query and search key in table (test.csv) has wildcard as shown below.

FILENAMEEMAIL
abc*test1@a.com
xyz*test2@a.com

 

The query should match fname in log file with FILENAME from lookup table and if there's a match then result should be something like:

FILENAMEEMAILcnt
abc*test1@a.com2
xyz*test2@a.com0

 

Instead my query output is:

fnameEMAILcount
abc*test1@a.com0
abc123.txt 1
abc.dat 1
xyz*test2@a.com

0

 

This is my query:

index=* host=* source="/bustools/*"
| rex max_match=100 "\d+\d+\s(?<ts>.*)\s(?<directory>\/.*)\/(?<fname>.*)"
| dedup fname
| search [ | inputlookup test.csv | rename FILENAME AS fname
| fields fname]
| stats count as occur by fname | append
[ inputlookup test.csv | rename FILENAME AS fname | fields fname]
| fillnull occur
| stats sum(occur) as cnt BY fname
| join type=left fname
[ | inputlookup test.csv | rename FILENAME AS fname]
| table fname EMAIL cnt

Any help would be appreciated.

Labels (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@rahul0621 

I have change the approach for your requirement. May me useful for you. Can you please try below search?

 

| inputlookup test.csv | eval fname = FILENAME | map search="index=* host=* source="/bustools/*" | rex max_match=100 "\d+\d+\s(?<ts>.*)\s(?<directory>\/.*)\/(?<fname>.*)" | dedup fname | search fname="$fname$" | stats count by fname | appendcols [ | makeresults |eval FILENAME="$FILENAME$",EMAIL="$EMAIL$"] | filldown FILENAME EMAIL " | fillnull count | stats sum(count) by FILENAME,EMAIL

 

Note:

 

This is my Sample Search in case you want to trace logic:

| makeresults | eval FILENAME="splunk_*",EMAIL="test1@a.com" | append [ | makeresults | eval FILENAME="splunkd_*",EMAIL="test2@a.com"] | append [ | makeresults | eval FILENAME="splunks_*",EMAIL="test3@a.com"] | table FILENAME EMAIL | rename comments as "This is lookup data" | eval fname = FILENAME | map search="search index=_internal | rename sourcetype as fname | dedup fname | search fname="$fname$" | stats count by fname | appendcols [ | makeresults |eval FILENAME="$FILENAME$",EMAIL="$EMAIL$"] | filldown FILENAME EMAIL " | fillnull count | stats sum(count) by FILENAME,EMAIL

 

 Thanks
Kamlesh Vaghela

View solution in original post

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@rahul0621 

I have change the approach for your requirement. May me useful for you. Can you please try below search?

 

| inputlookup test.csv | eval fname = FILENAME | map search="index=* host=* source="/bustools/*" | rex max_match=100 "\d+\d+\s(?<ts>.*)\s(?<directory>\/.*)\/(?<fname>.*)" | dedup fname | search fname="$fname$" | stats count by fname | appendcols [ | makeresults |eval FILENAME="$FILENAME$",EMAIL="$EMAIL$"] | filldown FILENAME EMAIL " | fillnull count | stats sum(count) by FILENAME,EMAIL

 

Note:

 

This is my Sample Search in case you want to trace logic:

| makeresults | eval FILENAME="splunk_*",EMAIL="test1@a.com" | append [ | makeresults | eval FILENAME="splunkd_*",EMAIL="test2@a.com"] | append [ | makeresults | eval FILENAME="splunks_*",EMAIL="test3@a.com"] | table FILENAME EMAIL | rename comments as "This is lookup data" | eval fname = FILENAME | map search="search index=_internal | rename sourcetype as fname | dedup fname | search fname="$fname$" | stats count by fname | appendcols [ | makeresults |eval FILENAME="$FILENAME$",EMAIL="$EMAIL$"] | filldown FILENAME EMAIL " | fillnull count | stats sum(count) by FILENAME,EMAIL

 

 Thanks
Kamlesh Vaghela

0 Karma

rahul0621
Explorer

@kamlesh_vaghela  I had to tweak it a bit but this approach worked perfectly. Thanks a lot for your quick help.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...