Splunk Search

How to change the source value in my search when I change the date time range?

sfatnass
Contributor

hi

I want to change the source on my request when the timechange.

I'll explain:
I have a lot of directories named by date and I use this as the source.

Example:

index=my_index source="20160513"

When I change the date, I need to change the source value.
So, if the earliest time search equals 20160522, then my search will be:

index=myindex source="20160522"

My test is:

index=myindex |addinfo | eval time1=strftime(info_min_time, "%Y%m%d")  |where source=time1 |table field1 field2 ......

but this doesn't work for me and I don't know how I can do this.

if any body have a solution thx

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try like this

index=myindex [| gentimes start=-1 | addinfo | eval source=strftime(info_min_time, "%Y%m%d") | table source ] | rest of your search

View solution in original post

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

index=myindex [| gentimes start=-1 | addinfo | eval source=strftime(info_min_time, "%Y%m%d") | table source ] | rest of your search
0 Karma

sfatnass
Contributor

It works very well.
What about if I want to search one day ago?
I tried this, but it does not work:

index=myindex [| gentimes start=-1 | addinfo | eval source=relative_time(strftime(info_min_time,"-1d@d"), "%Y%m%d") | table source ]
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...