Splunk Search

How do you display the last 4 months in Splunk starting from the current month?

sbhatnagar88
Path Finder

How do you display the last 4 months in Splunk starting from the current month?

Required output is:

January 2019
December 2018
November 2018
October 2018

Tags (1)
0 Karma
1 Solution

renjith_nair
SplunkTrust
SplunkTrust

@sbhatnagar88 ,

Try

 |makeresults
 |eval months=strftime(mvrange(relative_time(_time,"-3mon@mon"),relative_time(_time,"@mon+1"),"1mon"),"%B %Y")
 |mvexpand months

Detailed/expanded version

|makeresults
|eval earliest=relative_time(_time,"-3mon@mon") 
|eval latest=relative_time(_time,"@mon+1")
|eval months=mvrange(earliest,latest,"1mon")
|eval months=strftime(months,"%B %Y")
|mvexpand months|table months
Happy Splunking!

View solution in original post

0 Karma

ryhluc01
Communicator

I believe you need to change the maximum amount of results your query can display before you can do this. Unless you're talking about the actual syntax query.

Are you talking about the query or about not being able to see 4 months of data?

0 Karma

renjith_nair
SplunkTrust
SplunkTrust

@sbhatnagar88 ,

Try

 |makeresults
 |eval months=strftime(mvrange(relative_time(_time,"-3mon@mon"),relative_time(_time,"@mon+1"),"1mon"),"%B %Y")
 |mvexpand months

Detailed/expanded version

|makeresults
|eval earliest=relative_time(_time,"-3mon@mon") 
|eval latest=relative_time(_time,"@mon+1")
|eval months=mvrange(earliest,latest,"1mon")
|eval months=strftime(months,"%B %Y")
|mvexpand months|table months
Happy Splunking!
0 Karma

sbhatnagar88
Path Finder

Great!! that works absolutely fine...thanks for help!!!

0 Karma

renjith_nair
SplunkTrust
SplunkTrust

@sbhatnagar88 , if it helped, please accept as answer

Happy Splunking!
0 Karma

richgalloway
SplunkTrust
SplunkTrust

@sbhatnagar88 If your problem is resolved, please accept an answer to help future readers.

---
If this reply helps you, Karma would be appreciated.
0 Karma

sbhatnagar88
Path Finder

Thanks much!! Problem has been solved...

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...