Splunk Search

Is there a way to optimize my join search?

monteirolopes
Communicator

Hi,

I did a report that lists users who have not logged on for more than 60 days and the status of users aren't disable/deleted on Active Directory. For this, I used the command join to merge the distinct searches.

Here is my search:

sourcetype=ActiveDirectory | dedup sAMAccountName | eval x = strptime(lastLogonTimestamp, "%H:%M.%S %p, %a %m/%d/%Y")  | where x < (now() - (86400 * 60)) | JOIN sAMAccountName [ search sourcetype="WinEventLog:Security"  EventCode != 4725 OR EventCode != 4726 | dedup user | eval sAMAccountName = user ] | table sAMAccountName, lastLogonTimestamp | rename sAMAccountName AS "User" lastLogonTimestamp AS "Last Login"

There is a way to optimize this search?

Best regards,
Lopes.

0 Karma
1 Solution

somesoni2
Revered Legend

Try like this

(sourcetype=ActiveDirectory) OR (sourcetype="WinEventLog:Security"  EventCode != 4725 OR EventCode != 4726)
| eval User=coalesce(sAMAccountName, user) | stats latest(lastLogonTimestamp) as lastLogonTimestamp values(sourcetype) as sourcetype by User | where strptime(lastLogonTimestamp, "%H:%M.%S %p, %a %m/%d/%Y") < relative_time(now(),"-60d")
| table User lastLogonTimestamp | rename lastLogonTimestamp AS "Last Login"

View solution in original post

somesoni2
Revered Legend

Try like this

(sourcetype=ActiveDirectory) OR (sourcetype="WinEventLog:Security"  EventCode != 4725 OR EventCode != 4726)
| eval User=coalesce(sAMAccountName, user) | stats latest(lastLogonTimestamp) as lastLogonTimestamp values(sourcetype) as sourcetype by User | where strptime(lastLogonTimestamp, "%H:%M.%S %p, %a %m/%d/%Y") < relative_time(now(),"-60d")
| table User lastLogonTimestamp | rename lastLogonTimestamp AS "Last Login"

dolivasoh
Contributor

Nice one. I didn't think of coalescing until after I posted and I was already heading to bed.

0 Karma

monteirolopes
Communicator

Thank you!

0 Karma

dolivasoh
Contributor

Try this

(sourcetype=ActiveDirectory) OR (sourcetype="WinEventLog:Security"  EventCode != 4725 OR EventCode != 4726) | eval x = strptime(lastLogonTimestamp, "%H:%M.%S %p, %a %m/%d/%Y")  | where x < (now() - (86400 * 60)) | rename user as sAMAccountName | stats latest(lastLogonTimestamp) as lastLogonTimestamp by sAMAccountName | rename sAMAccountName AS "User" lastLogonTimestamp AS "Last Login"
0 Karma
Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

New Release | Splunk Cloud Platform 10.1.2507

Hello Splunk Community!We are thrilled to announce the General Availability of Splunk Cloud Platform 10.1.2507 ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

&#x1f5e3; You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...