Splunk Search

Basic Query using Dates

modulussplunk
Loves-to-Learn

We have indexed fields like the following:

fname (a-z*)
lname (a-z*)
pdate (name_month day year)
policy ( strong or weak)

I'm able to do a query and returned all of the usernames with a strong policy (policy = 'strong').

If I try to also query for a password change date prior to May 1st (pdate > 'May 25 2019'), I get results with users that have password changes after that date.

I believe I need to somehow convert the date perhaps with the strftime function, because maybe it's not comparing the the fields as dates, but how would I do that and actually construct the query? I've read the docs and tried some copy/pastes w/o a working solution.

Thanks

Tags (1)
0 Karma

bandit
Motivator

So the first question is. Can you index pdate as your _time field?

If pdate is not indexed as the _time field i.e. primary time key you cannot use it to search with the default time picker dropdowns or search command line time modifiers. I believe you would have to convert to epoch time first etc. and then compare to current time in epoch time to do a calculation for more than 30 days. Essentially you are converting pdate to epoch time seconds a number that you can use > = or < to compare against.

For converting dates to a number see:
https://answers.splunk.com/answers/595091/converting-date-to-epoch-time.html

0 Karma

modulussplunk
Loves-to-Learn

Thanks rob_jordan. I should have mentioned. I don't need to search with the default time picker drop downs, but 'within' search bar itself. We feed the data daily so the default time picker drop down doesn't mean too much. We actually use the dedup command on the search bar.

But, I apologize. That link might make sense to you or others but I'm just getting started with Splunk. I'm still a bit unsure of the syntax. From my understanding, it seems like it would the search query look something like, this?

index="blah1" sourcetype="blah2" policy = "strong" mypdate > ($epoch_number_for_desired_date)| eval mypdate = strptime('mypdate', "%m %d %y")

Thank you

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...