<?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 Convert string format to time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67792#M16942</link>
    <description>&lt;P&gt;One log line from LDAP log file&lt;/P&gt;

&lt;P&gt;= ==================================&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Sep 19 10:08:10 simxxx11 slapd_simxxx11[4274]: conn=3012 fd=52 ACCEPT from IP=10.100.10.102:53530 (IP=0.0.0.0:636)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can capture the STARTTIME of the LDAP connection with a regular expression, but this gives me back a string. When I capture the STARTTIME using &lt;CODE&gt;rex "(?P&amp;lt;STARTTIME&amp;gt;\w+\s+\d+\s+\d+:\d+:\d+).+conn=\d+ fd=\d+ ACCEPT.+"&lt;/CODE&gt; then I have the value &lt;CODE&gt;Sep 19 10:08:12&lt;/CODE&gt; in variable STARTTIME. I want to convert it to a time format. &lt;/P&gt;

&lt;P&gt;I have tried &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;strptime(STARTTIME,"%Y-%m-%dT%H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this does not work. &lt;BR /&gt;
Another log line from LDAP log file&lt;/P&gt;

&lt;P&gt;===================================&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Sep 19 10:08:12 simxxx11 slapd_simxxx[4274]: conn=3012 fd=52 closed
"(?P&amp;lt;ENDTIME&amp;gt;\w+\s+\d+\s+\d+:\d+:\d+).+ conn=\d+ fd=\d+ closed"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to find the difference between the STARTTIME and ENDTIME.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2013 11:29:24 GMT</pubDate>
    <dc:creator>sgoyal</dc:creator>
    <dc:date>2013-09-19T11:29:24Z</dc:date>
    <item>
      <title>Convert string format to time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67792#M16942</link>
      <description>&lt;P&gt;One log line from LDAP log file&lt;/P&gt;

&lt;P&gt;= ==================================&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Sep 19 10:08:10 simxxx11 slapd_simxxx11[4274]: conn=3012 fd=52 ACCEPT from IP=10.100.10.102:53530 (IP=0.0.0.0:636)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can capture the STARTTIME of the LDAP connection with a regular expression, but this gives me back a string. When I capture the STARTTIME using &lt;CODE&gt;rex "(?P&amp;lt;STARTTIME&amp;gt;\w+\s+\d+\s+\d+:\d+:\d+).+conn=\d+ fd=\d+ ACCEPT.+"&lt;/CODE&gt; then I have the value &lt;CODE&gt;Sep 19 10:08:12&lt;/CODE&gt; in variable STARTTIME. I want to convert it to a time format. &lt;/P&gt;

&lt;P&gt;I have tried &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;strptime(STARTTIME,"%Y-%m-%dT%H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this does not work. &lt;BR /&gt;
Another log line from LDAP log file&lt;/P&gt;

&lt;P&gt;===================================&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Sep 19 10:08:12 simxxx11 slapd_simxxx[4274]: conn=3012 fd=52 closed
"(?P&amp;lt;ENDTIME&amp;gt;\w+\s+\d+\s+\d+:\d+:\d+).+ conn=\d+ fd=\d+ closed"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to find the difference between the STARTTIME and ENDTIME.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2013 11:29:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67792#M16942</guid>
      <dc:creator>sgoyal</dc:creator>
      <dc:date>2013-09-19T11:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string format to time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67793#M16943</link>
      <description>&lt;P&gt;If the timestamps you want to use for your calculations are in fact the timestamps that have been used when indexing the events, that information is available in the &lt;CODE&gt;_time&lt;/CODE&gt; field as an epoch value (which are great for mathematical operations).&lt;/P&gt;

&lt;P&gt;There are several ways in which you can achieve this;&lt;/P&gt;

&lt;P&gt;With a &lt;CODE&gt;transaction&lt;/CODE&gt;, assuming that &lt;CODE&gt;conn&lt;/CODE&gt; is a unique id for this connection (or at least unique within an hour or so). &lt;CODE&gt;transaction&lt;/CODE&gt; automatically creates a new field called &lt;CODE&gt;duration&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_base_search | transaction conn maxevents=2 maxspan=1m startswith="ACCEPT" endswith="closed" | table conn duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With &lt;CODE&gt;stats&lt;/CODE&gt;. Assumptions as before.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_base_search | stats min(_time) AS StartTime max(_time) AS EndTime by conn | eval dur = tostring((EndTime - StartTime), "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You could also look at the &lt;CODE&gt;convert&lt;/CODE&gt; command instead of the &lt;CODE&gt;eval/tostring&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;Some interesting reading:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Stats"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Stats&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonStatsFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonStatsFunctions&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Eval"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Eval&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2013 12:46:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67793#M16943</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-19T12:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string format to time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67794#M16944</link>
      <description>&lt;P&gt;Thank you Kristian. Actually for a transaction based on conn, I can calculate the duration. But I want to calculate the individual BIND delays and SEARCH delays inside the transaction.Each operation inside a transaction has a unique op value. How can I use it to get to the individual delays.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2013 11:32:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67794#M16944</guid>
      <dc:creator>sgoyal</dc:creator>
      <dc:date>2013-09-20T11:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string format to time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67795#M16945</link>
      <description>&lt;P&gt;Sorry, but I don't know the structure of your transactions. LDAP is not my strongest side. Is it something like;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;conn_1_start&lt;BR /&gt;
    op_1_start&lt;BR /&gt;
    op_1_end&lt;BR /&gt;
    op_2_start&lt;BR /&gt;
    op_2_end&lt;BR /&gt;
conn_1_end&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Or is it more like;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;conn_1_start&lt;BR /&gt;
   op_1_timestamp&lt;BR /&gt;
   op_2_timestamp&lt;BR /&gt;
   op_3_timestamp&lt;BR /&gt;
conn_1_end&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;You should probably post a few more sample events, highlighting which timstamps you need to compute durations for.&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2013 12:31:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-string-format-to-time/m-p/67795#M16945</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-20T12:31:46Z</dc:date>
    </item>
  </channel>
</rss>

