Splunk Search

strptime works when using makeresults, but not with actual results

raoul
Path Finder

I have a dataset of user data including the user's LastLogin. The LastLogin field is slightly oddly formatted but very regular in it's pattern. I wish to calculate the number of days since LastLogin. This should be super simple.

What is bizarre is that in a contrived example using makeresults it works perfectly.

 

| makeresults
| eval LastLogin="Mar 20, 2024, 16:40"
| eval lastactive=strptime(LastLogin, "%b %d, %Y, %H:%M")
| eval dayslastactive=round((now() - lastactive) / 86000, 0)

 

This yields:

2024-04-02_13-46-05.png

But with the actual results the same transformations do not work. 

 

| inputlookup MSOLUsers 
| where match(onPremisesDistinguishedName, "OU=Users") 
| where not isnull(LastLogin)
| eval LastActive=strptime(LastLogin, "%b %d, %Y, %H:%M")
| eval DaysLastActive=round((now() - LastActive) / 86000, 0)
| fields Company, Department, DisplayName, LastLogin, LastActive, DaysLastActive

 

This yields:

2024-04-02_13-50-23.png

What am I missing? Cutting and pasting the strings into the makeresults form gives what I would expect. 

 

 

Labels (1)
Tags (1)
0 Karma
1 Solution

scelikok
SplunkTrust
SplunkTrust

Hi @raoul,

Maybe spaces in your LastLogin field are unprintable characters. Can you try below query which cleans all whitespace?

| inputlookup MSOLUsers 
| where match(onPremisesDistinguishedName, "OU=Users") 
| where not isnull(LastLogin)
| eval LastLogin=replace(LastLogin,"[^A-Za-z0-9,:]+","")
| eval LastActive=strptime(LastLogin, "%b%d,%Y,%H:%M")
| eval DaysLastActive=round((now() - LastActive) / 86000, 0)
| fields Company, Department, DisplayName, LastLogin, LastActive, DaysLastActive
If this reply helps you an upvote and "Accept as Solution" is appreciated.

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Minor point, but the number of seconds in a day is 86400, not 86000.

scelikok
SplunkTrust
SplunkTrust

Hi @raoul,

Maybe spaces in your LastLogin field are unprintable characters. Can you try below query which cleans all whitespace?

| inputlookup MSOLUsers 
| where match(onPremisesDistinguishedName, "OU=Users") 
| where not isnull(LastLogin)
| eval LastLogin=replace(LastLogin,"[^A-Za-z0-9,:]+","")
| eval LastActive=strptime(LastLogin, "%b%d,%Y,%H:%M")
| eval DaysLastActive=round((now() - LastActive) / 86000, 0)
| fields Company, Department, DisplayName, LastLogin, LastActive, DaysLastActive
If this reply helps you an upvote and "Accept as Solution" is appreciated.
Get Updates on the Splunk Community!

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 at Splunk .conf24 ...

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

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...