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
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In November, the Splunk Threat Research Team had one release of new security content via the Enterprise ...

Index This | Divide 100 by half. What do you get?

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

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

❄️ Celebrate the season with our December lineup of Community Office Hours, Tech Talks, and Webinars! ...