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!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...