Splunk Enterprise

How to dynamically lookup filename?

Thulasinathan_M
Communicator

Hello Splunk Experts,
I've tried below query to use the 'previous_day' field in inputlookup and save it in outputlookup using today and append results if the file for today is not created. But it's not working. Could anyone please correct me on what I'm doing wrong here. Thanks in advance!!

 

 

index=test *exception

| [ | eval previous_day="lookup" .strftime(relative_time(now(), "-1d"), "%m%d"). ".csv"
    | inputlookup $previous_day$ ]
| eval today="lookup" .strftime(now(), "%m%d"). ".csv"
| [| inputlookup $today$ 
    | eval is_append= if(isnull(Exception), "append=1", "")]
| stats count by first(_raw) as Exception
| outputlookup $today$ $is_append$

 

 

Labels (1)
Tags (1)
0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

it works something like this

<our base search here>
| append 
    [| inputlookup 
        [| makeresults 
        | eval search="result_".strftime(relative_time(now(), "-1d"),"%Y_%m_%d").".csv" 
        | table search]] 
| append 
    [| inputlookup 
        [| makeresults 
        | eval search="result_".strftime(now(),"%Y_%m_%d").".csv" 
        | table search]]

| <rest of your data manipulation here>

| outputlookup  
       [| makeresults 
        | eval search="result_".strftime(now(),"%Y_%m_%d").".csv" 
        | table search] 
       [| makeresults
        | eval search = if(isnull(Exception), "append=1", "")
        | table search]

 There could be something what you need to change, but basic idea is here.

View solution in original post

isoutamo
SplunkTrust
SplunkTrust
0 Karma

Thulasinathan_M
Communicator

I checked this post, but will this work in my case with inputlookup/ inputcsv as well. Could you please elaborate..

0 Karma

isoutamo
SplunkTrust
SplunkTrust

it works something like this

<our base search here>
| append 
    [| inputlookup 
        [| makeresults 
        | eval search="result_".strftime(relative_time(now(), "-1d"),"%Y_%m_%d").".csv" 
        | table search]] 
| append 
    [| inputlookup 
        [| makeresults 
        | eval search="result_".strftime(now(),"%Y_%m_%d").".csv" 
        | table search]]

| <rest of your data manipulation here>

| outputlookup  
       [| makeresults 
        | eval search="result_".strftime(now(),"%Y_%m_%d").".csv" 
        | table search] 
       [| makeresults
        | eval search = if(isnull(Exception), "append=1", "")
        | table search]

 There could be something what you need to change, but basic idea is here.

Thulasinathan_M
Communicator

Thanks, worked like a charm!! 🙂

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud | Customer Survey!

If you use Splunk Observability Cloud, we invite you to share your valuable insights with us through a brief ...

.conf23 | Get Your Cybersecurity Defense Analyst Certification in Vegas

We’re excited to announce a new Splunk certification exam being released at .conf23! If you’re going to Las ...

Starting With Observability: OpenTelemetry Best Practices

Tech Talk Starting With Observability: OpenTelemetry Best Practices Tuesday, October 17, 2023   |  11AM PST / ...