Splunk Search

Append lookup to results with where clause

dataisbeautiful
Communicator

Hi all

I am trying to append data to results based on a file.

Example temperature and pressure are stored at 1 sample per minute all the time. The times when a batch was in production is logged in a look up file. Batch IDs are generated and stored after logging of sensor values to Splunk.

Base search:

index=ndx sourcetype=srctp (sensor=temperature OR sensor=pressure) earliest=-1d@d latest=@d
| table _time sensor value

Result:

_timesensorvalue
...temperature75
...pressure100

 

Look up file has 3 columns, the start and finish time for a batch and the ID

startTimefinishTimebatchID
......b1
......b2
......b3

 

For each row in the result table of the base search, I want to append the batch ID to give

_timesensorvaluebatchID
...temperature75b2
...pressure100b2

 

I have tried with

| lookup batch.csv _time >= startTime, _time <= finishTime OUTPUTNEW batchID 

The lookup needs to find a batch where the value of _time >= startTime AND _time<=finishTime

I can't see anything for lookup that works with this sort of conditions. Only where fields are a direct match.

Any ideas would be appreciated, thanks in advance.

Labels (1)
0 Karma
1 Solution

dataisbeautiful
Communicator

I figured it out

| lookup batch.csv OUTPUT startTime finishTime
| eval startTime = max(mvmap(startTime, if(startTime <= _time, startTime, null())))
| eval finishTime = min(mvmap(finishTime, if(finishTime >= _time, finishTime, null())))
| lookup batch.csv startTime finishTime OUTPUT batchID 

View solution in original post

0 Karma

dataisbeautiful
Communicator

I figured it out

| lookup batch.csv OUTPUT startTime finishTime
| eval startTime = max(mvmap(startTime, if(startTime <= _time, startTime, null())))
| eval finishTime = min(mvmap(finishTime, if(finishTime >= _time, finishTime, null())))
| lookup batch.csv startTime finishTime OUTPUT batchID 
0 Karma

livehybrid
Champion

Hi @dataisbeautiful 

Do the timings of batches overlap? Presumably if you had a batch starting each day at midnight, the batch you would be looking for would be the previous midnight?

If that is the case then you may be able to look at using a time-based lookup, just using the start time of the batches as the lookup field. This should work by returning the batch number where the _time of the event is after the start_time for that batch (and less than the start_time of the next batch) - if that makes sense?

Have a look at:

https://community.splunk.com/t5/Splunk-Search/How-to-configure-a-time-based-lookup-Temporal-lookup/m...

https://docs.splunk.com/Documentation/Splunk/9.4.0/Knowledge/Defineatime-basedlookupinSplunkWeb

Please let me know how you get on and consider accepting this answer or adding karma this answer if it has helped.
Regards

Will

  

0 Karma

dataisbeautiful
Communicator

Hi @livehybrid thanks for the links.

I'll add more details about the batches. They can be 1min in length to several hours. They are not regular in length unfortunately, it depends on the process and numbers etc. There may be several batches in a day too, up to 50 on some days.

 

Looking at: https://docs.splunk.com/Documentation/Splunk/9.4.0/Knowledge/Defineatime-basedlookupinSplunkWeb

If we pre-set a lookahear time, this could be too short and not give an ID or too big and give mutiple IDs?

 

Looking at: https://community.splunk.com/t5/Splunk-Search/How-to-configure-a-time-based-lookup-Temporal-lookup/m...

I can do a search for a single result using | inputlookup and | addinfo, that works fine. It's doing this on a FOR loop for each result that I'm stuck with.

 

I've tried this, but feels very inefficient

  • Add a column with just the date
  • Lookup all ID for the date
  • Use mvexpand to split multiple IDs into single events
  • Lookup for start and finish times for id
  • Where to filter on _time between start and finish
0 Karma
Get Updates on the Splunk Community!

Announcing the Expansion of the Splunk Academic Alliance Program

The Splunk Community is more than just an online forum — it’s a network of passionate users, administrators, ...

Learn Splunk Insider Insights, Do More With Gen AI, & Find 20+ New Use Cases You Can ...

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

Buttercup Games: Further Dashboarding Techniques (Part 7)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...