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 (2)
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

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!

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 ...

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 ...

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 ...