Splunk Search

How to generate a baseline on a timechart using a value from a lookup table

beetlegeuse
Path Finder

I have a search that captures a specific product code, calculates the total number of units attributed to the product code that were sold over the timeframe assigned to the search (say, seven days), and presents the data as a timechart. The search also references a lookup table to provide a "human friendly" name that matches the product code, along with a baseline value which reflects a specific number of units expected to be sold each day.

The search looks like this...

sourcetype=foo index=bar item="productA" 
| lookup product_table.csv productCode AS item
| timechart span=1d sum(product_count) as volume by item
| eval baseline = max(dailyBaseline)

 

...and the lookup table looks like this:

productCodenamedailyBaseline
productAWidget5000
productBThingamajig10000

 

I would like the ensuing chart to show the baseline I've defined in the lookup table. If I replace "max(dailyBaseline)" in the eval statement with a static value such as 5000, it works fine. I can't figure out how to get the "dailyBaseline" value from the lookup table to work, though.

Labels (3)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

The above assumes that your lookup file contents show is not the one where you are looking up against product_table.csv but if it's the same table, what are you trying to get from your lookup in the current command?

If you only have one lookup then what you want is

sourcetype=foo index=bar item="productA" 
| lookup product_table.csv productCode AS item
| timechart span=1d max(dailyBaseline) as baseline sum(product_count) as volume by name

 

View solution in original post

yuanliu
SplunkTrust
SplunkTrust

Do you mean something like this?

sourcetype=foo index=bar item="productA" 
| lookup product_table.csv productCode AS item
| timechart span=1d sum(product_count) as volume by name
| lookup product_table.csv name output dailyBaseline

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Here's one way you can do it by adding this after your timechart command

 

| foreach * [ eval productCode="<<FIELD>>" | lookup baseline.csv productCode OUTPUT name dailyBaseline | eval {name}=<<FIELD>>, base_{name}=dailyBaseline | fields - productCode name dailyBaseline "<<FIELD>>" ]

 

after a split by clause the column name is the productCode, so the foreach * will iterate through the columns and create a field called dailyBaseline_productX for each found value.

There will be other ways

Edit: Added friendly name mapping

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The above assumes that your lookup file contents show is not the one where you are looking up against product_table.csv but if it's the same table, what are you trying to get from your lookup in the current command?

If you only have one lookup then what you want is

sourcetype=foo index=bar item="productA" 
| lookup product_table.csv productCode AS item
| timechart span=1d max(dailyBaseline) as baseline sum(product_count) as volume by name

 

ITWhisperer
SplunkTrust
SplunkTrust

Given that your search is restricting your items to just one product (code), you could do the lookup after the timechart

sourcetype=foo index=bar item="productA" 
| timechart span=1d sum(product_count) as volume by item
| eval item="productA"
| lookup product_table.csv productCode AS item output dailyBaseline
| fields - item
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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...