Splunk Search

How do I count events for the past 45 days when the start date is the 15th of each month?

amilavsky
Engager

Please Help !!!!

I am trying to create an SPL query to count events for the past 45 days from the start date the 15th of each month, so for instance, January 15 through the past 45 days.

index=okta  earliest=-45d@d latest="1/15/2019:24:00:00" 
| stats min(_time) as lt max(_time) as ft dc(targets{}.login) as unique_user_count
| convert ctime(lt) as start_time
| convert ctime(ft) as end_time
| table start_time,end_time,unique_user_count
| append
[ search index=okta earliest=-45d@d latest="12/15/2018:24:00:00" 
| stats min(_time) as lt max(_time) as ft dc(targets{}.login) as unique_user_count
| convert ctime(lt) as start_time
| convert ctime(ft) as end_time
| table start_time,end_time,unique_user_count
]
  1. I'm trying to avoid hardcode latest time.
  2. earliest=-45d@d does not calculate the correct date from latest="1/15/2019:24:00:00". it's showing Dec7 instead of Dec2
  3. start_time duplicated data from first row
Tags (1)
0 Karma
1 Solution

bangalorep
Communicator

Hello,
- You could use tokens for the latest time if you want to add this in a dashboard
- You could refer to this documentation for snapping the time https://docs.splunk.com/Documentation/Splunk/7.2.3/SearchReference/SearchTimeModifiers
- Could you please elaborate a bit more on this problem?

View solution in original post

0 Karma

mstjohn_splunk
Splunk Employee
Splunk Employee

hi @amilavsky,

Did you have a chance to check out bangalorep 's answer? If it worked, please resolve this post by approving it! If your problem is still not solved, keep us updated so that someone else can help ya.

0 Karma

bangalorep
Communicator

Hello,
- You could use tokens for the latest time if you want to add this in a dashboard
- You could refer to this documentation for snapping the time https://docs.splunk.com/Documentation/Splunk/7.2.3/SearchReference/SearchTimeModifiers
- Could you please elaborate a bit more on this problem?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...