<?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: Extract value from multiple events and find time delta in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Extract-value-from-multiple-events-and-find-time-delta/m-p/448566#M77969</link>
    <description>&lt;P&gt;Try this: Watchout for your single quotes in the code. I have blindly used your raw data. Tweak the code as per your needs. Accept and/or upvote my reply if it helps. Good luck.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults 
| eval _raw=" {‘job_id,:’1’, ‘stage_state’:’build_begin’,’stage_type:’build’,’start_time’:’2019-08-15 15:00:00’} "
|append[
|makeresults 
| eval _raw="
{‘job_id,:’1’, ‘stage_state’:’build_end’,’stage_type:’build’,’end_time’:’2019-08-15 15:10:00’} "]
|append[
|makeresults 
| eval _raw="
{‘job_id,:’1’, ‘stage_state’:’exc_begin’,’stage_type:’exec’,’start_time’:’2019-08-15 15:10:01’}"]
|append[
|makeresults 
| eval _raw="
{‘job_id,:’1’, ‘stage_state’:’exc_end’,’stage_type:’exec’,’end_time’:’2019-08-15 15:20:00’} " ]
 `comment("Don't worry about anything above this line. It's just used for generating your raw data")`

| rex field=_raw "\’stage_type\:\’(?&amp;lt;Type&amp;gt;.*?)\s*\’\," 
|rex field=_raw "\’start_time\’\:\’(?&amp;lt;Start_Time&amp;gt;.*?)\s*\’" 
|rex field=_raw "\’end_time\’\:\’(?&amp;lt;End_Time&amp;gt;.*?)\s*\’" 
|rex field=_raw "\‘job_id\,\:\’(?&amp;lt;job_id&amp;gt;\d+)\’\," 
| transaction job_id startswith="end_time" endswith="start_time" 
| eval Diff_in_secs=strptime(End_Time, "%Y-%m-%d %H:%M:%S.%3N")-strptime(Start_Time, "%Y-%m-%d %H:%M:%S.%3N")
| eventstats sum(Diff_in_secs) as TotalDiff_in_secs
|table Start_Time End_Time Type Diff_in_secs TotalDiff_in_secs
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Aug 2019 06:15:14 GMT</pubDate>
    <dc:creator>nareshinsvu</dc:creator>
    <dc:date>2019-08-16T06:15:14Z</dc:date>
    <item>
      <title>Extract value from multiple events and find time delta</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extract-value-from-multiple-events-and-find-time-delta/m-p/448565#M77968</link>
      <description>&lt;P&gt;Sample log data &lt;BR /&gt;
{‘job_id,:’1’, ‘stage_state’:’build_begin’,’stage_type:’build’,’start_time’:’2019-08-15 15:00:00’}&lt;BR /&gt;
{‘job_id,:’1’, ‘stage_state’:’build_end’,’stage_type:’build’,’endtime’:’2019-08-15 15:10:00’}&lt;BR /&gt;
{‘job_id,:’1’, ‘stage_state’:’exc_begin’,’stage_type:’exec’,’start_time’:’2019-08-15 15:10:01’}&lt;BR /&gt;
stage_state’:’exc_end’,’stage_type:’exec’,’end_time’:’2019-08-15 15:20:00’}&lt;/P&gt;

&lt;P&gt;I am trying get a table like this output &lt;BR /&gt;
Job_id stage time taken&lt;/P&gt;

&lt;P&gt;1         Build.     10&lt;BR /&gt;
1        Exc.       10&lt;BR /&gt;
1     Total.     20&lt;/P&gt;

&lt;P&gt;I am new to Splunk I tried a few things but. I cannot get nothing close to expected answer&lt;BR /&gt;&lt;BR /&gt;
Thanks &lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:45:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extract-value-from-multiple-events-and-find-time-delta/m-p/448565#M77968</guid>
      <dc:creator>vanakkam</dc:creator>
      <dc:date>2020-09-30T01:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from multiple events and find time delta</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extract-value-from-multiple-events-and-find-time-delta/m-p/448566#M77969</link>
      <description>&lt;P&gt;Try this: Watchout for your single quotes in the code. I have blindly used your raw data. Tweak the code as per your needs. Accept and/or upvote my reply if it helps. Good luck.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults 
| eval _raw=" {‘job_id,:’1’, ‘stage_state’:’build_begin’,’stage_type:’build’,’start_time’:’2019-08-15 15:00:00’} "
|append[
|makeresults 
| eval _raw="
{‘job_id,:’1’, ‘stage_state’:’build_end’,’stage_type:’build’,’end_time’:’2019-08-15 15:10:00’} "]
|append[
|makeresults 
| eval _raw="
{‘job_id,:’1’, ‘stage_state’:’exc_begin’,’stage_type:’exec’,’start_time’:’2019-08-15 15:10:01’}"]
|append[
|makeresults 
| eval _raw="
{‘job_id,:’1’, ‘stage_state’:’exc_end’,’stage_type:’exec’,’end_time’:’2019-08-15 15:20:00’} " ]
 `comment("Don't worry about anything above this line. It's just used for generating your raw data")`

| rex field=_raw "\’stage_type\:\’(?&amp;lt;Type&amp;gt;.*?)\s*\’\," 
|rex field=_raw "\’start_time\’\:\’(?&amp;lt;Start_Time&amp;gt;.*?)\s*\’" 
|rex field=_raw "\’end_time\’\:\’(?&amp;lt;End_Time&amp;gt;.*?)\s*\’" 
|rex field=_raw "\‘job_id\,\:\’(?&amp;lt;job_id&amp;gt;\d+)\’\," 
| transaction job_id startswith="end_time" endswith="start_time" 
| eval Diff_in_secs=strptime(End_Time, "%Y-%m-%d %H:%M:%S.%3N")-strptime(Start_Time, "%Y-%m-%d %H:%M:%S.%3N")
| eventstats sum(Diff_in_secs) as TotalDiff_in_secs
|table Start_Time End_Time Type Diff_in_secs TotalDiff_in_secs
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Aug 2019 06:15:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extract-value-from-multiple-events-and-find-time-delta/m-p/448566#M77969</guid>
      <dc:creator>nareshinsvu</dc:creator>
      <dc:date>2019-08-16T06:15:14Z</dc:date>
    </item>
  </channel>
</rss>

