Splunk Search

Specifying today's date in the source file on a search

DavidGuarneri
Path Finder

Is there a way to specify today's date in the filename of the source on the search? I'm thinking in the same way you would put it in a bash script. Pseudocode:

source="C:logs\\path\\iislog_(time(%y%m%d)).log"

Tags (2)
0 Karma

yannK
Splunk Employee
Splunk Employee

use the function now() in a subsearch or a macro.

the search to generate a condition :

| stats count | eval date=strftime(now(),"%Y%m%d") | eval source="C:logs\\path\\iislog_".date.".log" | table source

the search using the sub search to generate a source condition

* [ | stats count | eval date=strftime(now(),"%Y%m%d") | eval source="C:logs\\path\\iislog_".date.".log" | table source]

you could improve by using a macro too.

Ayn
Legend

Use a subsearch:

[| stats count | eval source="C:\\logs\\path\\iislog".strftime(now(),"%y%m%d").".log" | fields source]

DavidGuarneri
Path Finder

That worked, thank you!

0 Karma

yannK
Splunk Employee
Splunk Employee

You are a kung fu master Ayn !

0 Karma
Get Updates on the Splunk Community!

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...