Splunk Search

Active Directory LastLogonTimestamp EVAL/WHERE Date Math

mcrawford44
Communicator

I'm attempting to locate systems that have not logged into AD for 90 days. I am using the following search;

index=foo   | where lastLogonTimestamp<relative_time(now(), "-90d" )  | dedup cn  | table  cn,lastLogonTimestamp,operatingSystem

This does not appear to function. It returns results, however the LastLogonTimestamp field appears to return ALL dates. Reversing the query returns garbage results. Every field returned says "OptionalProperties".

If I recall, this variable is stored in some Microsoft tick time similar to epoch, however Splunk seems to display it properly in the following format;

07:44.36 PM, Sun 11/17/2013

Is Splunk automatically converting this? Do I have to define a format in order to evaluate or use a where command?

0 Karma
1 Solution

kristian_kolb
Ultra Champion

Most likely you'll need to convert the lastLogonTimestamp to epoch before making the comparison.

index=foo lastLogonTimestamp=* 
| eval last_logon = strptime(lastLogonTimestamp, "%H:%M.%S %p, %a %m/%d/%Y") 
| where last_logon < (now() - (86400 * 90)) 
| dedup cn 
| table cn, lastLogonTimestamp, operatingsystem

hope this helps,

k

View solution in original post

kristian_kolb
Ultra Champion

Most likely you'll need to convert the lastLogonTimestamp to epoch before making the comparison.

index=foo lastLogonTimestamp=* 
| eval last_logon = strptime(lastLogonTimestamp, "%H:%M.%S %p, %a %m/%d/%Y") 
| where last_logon < (now() - (86400 * 90)) 
| dedup cn 
| table cn, lastLogonTimestamp, operatingsystem

hope this helps,

k

monteirolopes
Communicator

Hi,
I would like to sort by date. If I use the command "sort -last_logon" , Splunk order by hours. Is it possible convert first to " %m/%d/%Y, %H:%M.%S %p"?

Best regards,
Lopes.

0 Karma

mcrawford44
Communicator

As a note I changed the %H to %I for 12-Hour time. Otherwise perfect and thank you very much for the help.

0 Karma

mcrawford44
Communicator

Perfect! Thank you.

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...