<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ldapsearch lastLogonTimestamp eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382524#M173039</link>
    <description>&lt;P&gt;Sorry, it was late and I copied from another search I was testing.  My first attempt should have been an eval for lltAge and NOT inactiveTime.  That line should have been this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval lltAge=now() - llt
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since llt is formatted, why does that not calculate?&lt;/P&gt;</description>
    <pubDate>Thu, 14 Feb 2019 13:32:03 GMT</pubDate>
    <dc:creator>s0mar</dc:creator>
    <dc:date>2019-02-14T13:32:03Z</dc:date>
    <item>
      <title>ldapsearch lastLogonTimestamp eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382521#M173036</link>
      <description>&lt;P&gt;I found this in a search:&lt;/P&gt;

&lt;P&gt;hxxps://&lt;A href="http://www.splunk.com/blog/2014/02/10/which-servers-are-inactive.html"&gt;www.splunk.com/blog/2014/02/10/which-servers-are-inactive.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;It is old but it describes exactly what I am trying to do but looking at user accounts.  I tried using the eval commands with my ldapsearch but I do not get any results.  I think I just don't understand what format lastLogonTimestamp is stored in.&lt;/P&gt;

&lt;P&gt;Here is my attempt to apply the information from the article:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| ldapsearch basedn="OU=MyOU,DC=my,DC=domain,DC=com" scope="sub" search="(objectClass=user)" attrs="cn,lastLogonTimestamp" 
| eval llt=strptime(lastLogonTimestamp,"%Y-%m-%dT%H:%M:%S.%QZ")
| eval inactiveTime=now() - llt
| table cn,lastLogonTimestamp,llt,lltAge
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run the search, lltAge is blank.&lt;/P&gt;

&lt;P&gt;What am I misunderstanding?&lt;/P&gt;

&lt;P&gt;I found another article and it gives me something more readable.&lt;BR /&gt;
hxxps://answers.splunk.com/answers/307865/converting-lastlogontimestamp-to-readable-date-and.html&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval llt=strftime(strptime(lastLogonTimestamp,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y/%m/%d %T %Z")
| eval lltAge=now() - llt 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I attempting to eventually do a where clause with lltAge&amp;gt;= 30 days or some value.&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 03:46:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382521#M173036</guid>
      <dc:creator>s0mar</dc:creator>
      <dc:date>2019-02-14T03:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: ldapsearch lastLogonTimestamp eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382522#M173037</link>
      <description>&lt;P&gt;Hi @s0mar,&lt;/P&gt;

&lt;P&gt;The first search example contains an error - the fields lltAge is never actually populated, so it can't show you any value.&lt;/P&gt;

&lt;P&gt;As for your requirement - finding accouts which did not login for the last 30 days:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| ldapsearch basedn="OU=MyOU,DC=my,DC=domain,DC=com" scope="sub" search="(objectClass=user)" attrs="cn,lastLogonTimestamp" 
| eval llt=strptime(lastLogonTimestamp,"%Y-%m-%dT%H:%M:%S.%QZ")
| where llt &amp;lt; relative_time(now(),"-30d")
| table cn, llt
| fieldformat llt = strftime(llt,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should give you the desired results.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 11:22:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382522#M173037</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2019-02-14T11:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: ldapsearch lastLogonTimestamp eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382523#M173038</link>
      <description>&lt;P&gt;@DMohn,&lt;/P&gt;

&lt;P&gt;Thanks!  I'll have to research to understand what you proposed.  So 2 things, how can test to see what this my eval is trying to do, specifically lltAge that is not populated?  I would like to perform that calculation so that I can output it as part of my table, what am I missing there?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 13:15:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382523#M173038</guid>
      <dc:creator>s0mar</dc:creator>
      <dc:date>2019-02-14T13:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: ldapsearch lastLogonTimestamp eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382524#M173039</link>
      <description>&lt;P&gt;Sorry, it was late and I copied from another search I was testing.  My first attempt should have been an eval for lltAge and NOT inactiveTime.  That line should have been this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval lltAge=now() - llt
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since llt is formatted, why does that not calculate?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 13:32:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382524#M173039</guid>
      <dc:creator>s0mar</dc:creator>
      <dc:date>2019-02-14T13:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: ldapsearch lastLogonTimestamp eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382525#M173040</link>
      <description>&lt;P&gt;One way is always to show all fields in your table. Going back to the original query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| ldapsearch basedn="OU=MyOU,DC=my,DC=domain,DC=com" scope="sub" search="(objectClass=user)" attrs="cn,lastLogonTimestamp" 
| eval llt=strptime(lastLogonTimestamp,"%Y-%m-%dT%H:%M:%S.%QZ")
| eval lltAge=now() - llt
| table cn,lastLogonTimestamp,llt,lltAge
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here you should see all 4 fields populated, the last two (&lt;CODE&gt;llt&lt;/CODE&gt; and &lt;CODE&gt;lltAge&lt;/CODE&gt;) showing a Unix timestamp. If this is not the case, you have to check why. Is &lt;CODE&gt;llt&lt;/CODE&gt; extracted correctly?  Try narrowing down where you are missing a calculation. &lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 13:54:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382525#M173040</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2019-02-14T13:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: ldapsearch lastLogonTimestamp eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382526#M173041</link>
      <description>&lt;P&gt;I am adding a comment here as well, so the information may be consistant in one answer thread.&lt;/P&gt;

&lt;P&gt;If you want to understand what your search does, it is always a good idea, to create as many fields as possible in the beginning, and narrowing it down to your final result going forward. So my above query could be enhanced like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| ldapsearch basedn="OU=MyOU,DC=my,DC=domain,DC=com" scope="sub" search="(objectClass=user)" attrs="cn,lastLogonTimestamp" 
| eval llt=strptime(lastLogonTimestamp,"%Y-%m-%dT%H:%M:%S.%QZ")
| eval lltAge = now()-llt
| where llt &amp;lt; relative_time(now(),"-30d")
| table cn, lastLogonTimestamp, llt, lltAge
| fieldformat llt = strftime(llt,"%Y-%m-%d %H:%M:%S")
| fieldformat lltAge = tostring(lltAge, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Explanation:&lt;BR /&gt;
1. Get information from AD&lt;BR /&gt;
2. convert lastLogonTimestamp to UNIX time &amp;lt;= be careful that the format is correct, double check if &lt;CODE&gt;llt&lt;/CODE&gt; is empty!&lt;BR /&gt;
3. calculate delta time of last logon&lt;BR /&gt;
4. select only entries where delta is greater than 30 days (could be done differently, but &lt;CODE&gt;lltAge&lt;/CODE&gt; is basically not needed&lt;BR /&gt;
5. display all fields in a table&lt;BR /&gt;
6. convert the field &lt;CODE&gt;llt&lt;/CODE&gt; to a more readable format without changing its actual value (consult manual for &lt;CODE&gt;fieldformat&lt;/CODE&gt; for details)&lt;BR /&gt;
7. convert &lt;CODE&gt;lltAge&lt;/CODE&gt; to a formatted duration, just like before&lt;/P&gt;

&lt;P&gt;I hope this helps your understanding.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 14:12:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382526#M173041</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2019-02-14T14:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: ldapsearch lastLogonTimestamp eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382527#M173042</link>
      <description>&lt;P&gt;Yes, that is what I did and then read some documentation.  Thanks for the answer!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 17:17:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/ldapsearch-lastLogonTimestamp-eval/m-p/382527#M173042</guid>
      <dc:creator>s0mar</dc:creator>
      <dc:date>2019-02-15T17:17:19Z</dc:date>
    </item>
  </channel>
</rss>

