Splunk Search

Extract data between multiple days..

Inayath_khan
Path Finder

Hi Guys,

I am just trying to write a spluNk query to extract data between 1-32 days , >32 days , > 42 days , > 72 days , < 365 days and < 720 days

I tried multiple queries and I believe it's possible with the case statement . Kindly suggest on this.

Note : I just have one custom field acd_date which I should use in my case statement.

Thanks in advance

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Perhaps this will get you started. It produces a 'period' field that you should be able to use for other purposes.

index=foo earliest=-720d latest=now
| eval epoch = strptime (acd_date, "<format of the acd_date field>")
| eval period = case(epoch < relative_time(now(), "-32d"), "1-32", epoch < relative_time(now(), "-42d"), ">32",
epoch < relative_time(now(), "-72d"), ">42", epoch < relative_time(now(), "-365d"), "<365", 1==1, "<720")
| ...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

to4kawa
Ultra Champion
| makeresults count=2 
| streamstats count 
| eval _time=if(count=2,relative_time(_time,(-1*count)."y@y"),_time) 
| makecontinuous span=1d _time 
| timechart count span=1d
| eval diff=tostring(now() - _time,"duration")
| rex field=diff "(?<daysAgo>\d+)\+"
| fillnull daysAgo
| eval acd_date=case(daysAgo <= 32 ,"less32days" , daysAgo <= 42, "less42days",  daysAgo <= 72,"less72days" , daysAgo <= 365,"less1year", daysAgo <= 720,"less2years",true(), "over2years")
| dedup acd_date

It's all about order.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Perhaps this will get you started. It produces a 'period' field that you should be able to use for other purposes.

index=foo earliest=-720d latest=now
| eval epoch = strptime (acd_date, "<format of the acd_date field>")
| eval period = case(epoch < relative_time(now(), "-32d"), "1-32", epoch < relative_time(now(), "-42d"), ">32",
epoch < relative_time(now(), "-72d"), ">42", epoch < relative_time(now(), "-365d"), "<365", 1==1, "<720")
| ...
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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