Splunk Search

How to append a value from lookup file to the event based on some condition

sangs8788
Communicator

I have a lookup file in below format
Product|R
AAAA|/ffff/*

I have some events i like R="/fff/abc" and some like R="/ffff/xyz.jsp"

Using this query i am able to fetch R counts
index=prod* |search [|inputlookup product-dashboard-lookup.csv |fields R ]|stats count as Rcount by R

Result for the above query is
R | Rcount
/fff/abc|10
/fff/xyz.jsp | 10

But i would like to get by Product instead of R something like below

AAAA | 20

How do i achieve this ?

Tags (1)
0 Karma

HiroshiSatoh
Champion

Try this!

index=prod*  [|inputlookup product-dashboard-lookup.csv |fields R ]
|lookup product-dashboard-lookup.csv R
|stats count as Rcount by ProductName
0 Karma

sangs8788
Communicator

Doesnt work since the R has wildcard in lookup file whereas the events contain the actual R.

0 Karma

HiroshiSatoh
Champion

You can use wild card for LOOKUP.
https://answers.splunk.com/answers/52580/can-we-use-wildcard-characters-in-a-lookup-table.html

If the number of cases is small, you can also use MAP.
| inputlookup product-dashboard-lookup.csv
| map [search index=prod* R=$R$|eval ProductName=$ProductName$]
| stats count as Rcount by ProductName
※We do not consider duplication and number limit.

It is complicated when there are many cases.
Please make your own with reference to the link below.
https://answers.splunk.com/answers/595766/need-to-display-zero-if-count-is-zero-for-data-tha.html

sangs8788
Communicator

Map does work. But the problem i am facing now is i am unable to add this as one of the panel in the Dashboard. It says "Search is waiting for Input". I guess its becuase of the dynamic parameter passed. How do i make the search as part of a Dashboard ?

0 Karma

HiroshiSatoh
Champion

Please tell us the search sentences and tokens you are using.

0 Karma

sangs8788
Communicator

Below is the query added as a panel to dashboard,

|inputlookup product-dashboard-lookup.csv |search Product=* AND R=* | map [search host=prod* R="$R$*" |eval Product="$Product$" ]|stats count by Product

The dashboard contains "Time" as input panel.

0 Karma

HiroshiSatoh
Champion

I made a grammar mistake. Also escape the double quotes.

|inputlookup product-dashboard-lookup.csv |search Product=* AND R=*
| map search="search host=prod* R=\"$R$*\" |eval Product=\"$Product$\""
|stats count by Product
0 Karma

sangs8788
Communicator

Still no luck. It is still waiting for input

0 Karma

sangs8788
Communicator

Individually both query works. But it doesnt work when added as a panel in a dashboard

0 Karma

somesoni2
Revered Legend

Wildcard lookup is the way to go here.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...