Splunk Search

using eval and time

PaulaCom
Path Finder

Afternoon All

i'd like some help please with some SPL logic that i just cant crack 😞 

I have data on some user in our Active Directory system and i am trying to:

create a new column with actions

identify those who have no logged in for more than 61 days and is so the action should return "reset password"

here's the part that i am having an issue with below. the first two lines are working as expected returning last_logon_total  day, month, year

i have a new field i created called 'action' that i want to return a value in of those users who have not logged in for more than 61 days.. but i cant get the spl right.

| eval epoch_lastLogonTimestamp_date = strptime(lastLogonTimestamp, "%Y-%m-%dT%H:%M:%S")
| eval last_logon_total = strftime(epoch_lastLogonTimestamp_date, "%d/%m/%Y")
| eval action = if(last_logon_total = relative_time(), "-61d@d", "reset password")



 

any ideas ?

 

Thanks

Paula  

 

Labels (3)
0 Karma
1 Solution

Richfez
SplunkTrust
SplunkTrust

There were a few errors, but this should work.  Note I broke out the comparison_date calculation from the eval where you decide if they need to reset or not, to a) make it more clear and b) so you can see the dates/strings it's comparing with.

| makeresults format="CSV" data="date
2024-05-09T08:05:00
2024-02-09T08:05:00"
| eval epoch_lastLogonTimestamp_date = strptime(date, "%Y-%m-%dT%H:%M:%S")
| eval last_logon_total = strftime(epoch_lastLogonTimestamp_date, "%d/%m/%Y")
| eval comparison_date = relative_time(now(),"-61d@d")
| eval action = if(epoch_lastLogonTimestamp_date <= comparison_date, "reset password", "no change needed")

 

I think the biggest issue was that the epoch date is the only one you need.  Do your math on it, work with it.  If you need to see it in a more human readable version, you can convert it back at the end.  In this case, 'last_logon_total' is simply unused after you build it.

 

Happy splunking, and if this helped karma would be appreciated!

-Rich

View solution in original post

PaulaCom
Path Finder

thanks this has worked perfectly. 

0 Karma

Richfez
SplunkTrust
SplunkTrust

There were a few errors, but this should work.  Note I broke out the comparison_date calculation from the eval where you decide if they need to reset or not, to a) make it more clear and b) so you can see the dates/strings it's comparing with.

| makeresults format="CSV" data="date
2024-05-09T08:05:00
2024-02-09T08:05:00"
| eval epoch_lastLogonTimestamp_date = strptime(date, "%Y-%m-%dT%H:%M:%S")
| eval last_logon_total = strftime(epoch_lastLogonTimestamp_date, "%d/%m/%Y")
| eval comparison_date = relative_time(now(),"-61d@d")
| eval action = if(epoch_lastLogonTimestamp_date <= comparison_date, "reset password", "no change needed")

 

I think the biggest issue was that the epoch date is the only one you need.  Do your math on it, work with it.  If you need to see it in a more human readable version, you can convert it back at the end.  In this case, 'last_logon_total' is simply unused after you build it.

 

Happy splunking, and if this helped karma would be appreciated!

-Rich

Get Updates on the Splunk Community!

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

&#x1f342; Fall into November with a fresh lineup of Community Office Hours, Tech Talks, and Webinars we’ve ...

Transform your security operations with Splunk Enterprise Security

Hi Splunk Community, Splunk Platform has set a great foundation for your security operations. With the ...

Splunk Admins and App Developers | Earn a $35 gift card!

Splunk, in collaboration with ESG (Enterprise Strategy Group) by TechTarget, is excited to announce a ...