Splunk Search

Find accounts with lastlogon older than X days

heidihart
Engager

Hi,

I have built out an AD inputlookup that includes lastlogon dates. When I attempt to find only those users with last logon older then 90 days I am unable to return any results.

| inputlookup AD.csv
| search lastLogon=* accountStatus!="ACCOUNTDISABLE"
| where lastLogon>=relative_time(now(),"-90d@d")
| table employee lastLogon

I have parsed the dates with strftime and strptime within the lookup itself and can see the dates are being displayed correctly but no luck on refining the results to just those of interest. I have tried to define the relative time, reparsing the dates within the search itself.

I have tried rearrange the date format and made sure to include the four year digits and still no luck.

Not sure what I am missing.

Any help would be appreciated

Tags (1)
0 Karma

manjunathmeti
Champion

Function relative_time gives output in epoch format. So you need to convert lastLogon to epoch before comparing.

Sample query:

| makeresults | eval somedate="2020-03-04 23:10:18", someepoch=strptime(somedate, "%Y-%m-%d %H:%M:%S") | where someepoch >= relative_time(now(),"-90d@d")

Modify your query, edit date time format in strptime function based on lastLogon values format:

| inputlookup AD.csv where lastLogon=* accountStatus!="ACCOUNTDISABLE"
| eval lastLogon=strptime(lastLogon, "%Y-%m-%d %H:%M:%S")
| where lastLogon>=relative_time(now(),"-90d@d")
| table employee lastLogon
0 Karma

heidihart
Engager

Perfect thanks that make sense now.

0 Karma

manjunathmeti
Champion

Please accept and upvote answer 🙂

Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...