<?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: Correlating Different Events and Calculating Time Difference in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252726#M189353</link>
    <description>&lt;P&gt;How many times these events can happen from one host in a day?&lt;/P&gt;</description>
    <pubDate>Fri, 18 Mar 2016 21:34:52 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-03-18T21:34:52Z</dc:date>
    <item>
      <title>Correlating Different Events and Calculating Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252724#M189351</link>
      <description>&lt;P&gt;I’m trying to report on the time difference between two related events.  Both events are collected from Windows event log and are in the same index.  They will occur on the same host but at different times and IDs.&lt;BR /&gt;
Example event data:&lt;/P&gt;

&lt;P&gt;Time: 3/11/2016 9:00:45 PM &lt;BR /&gt;
EventID: 1000 &lt;BR /&gt;
Source: Backup Agent Message: &lt;BR /&gt;
Backup Started &lt;BR /&gt;
Host: Server1 &lt;BR /&gt;
Time: 3/12/2016 1:09:45 AM&lt;/P&gt;

&lt;P&gt;EventID: 1001&lt;BR /&gt;
Source: Backup Agent&lt;BR /&gt;
Message: Backup Completed&lt;BR /&gt;
Host: Server1&lt;/P&gt;

&lt;P&gt;The second event can occur any time after the first, maybe in a few minutes or a few hours.  I’m thinking I need to find event 1(1000) first and then look for the first occurrence of event 2 afterwards.  The index would contain similar events from many hosts around the same time.&lt;BR /&gt;
I’ve tried various attempts with joins, transactions, and subsearches and searching the documentation for suggestions with no luck.  I’m really not concerned with any of the data in the event other than the time (which I would eval to a start and end time).  The goal is to be able to run a report over a time span to show the start/end times for each host.&lt;/P&gt;

&lt;P&gt;This gets me close but doesn’t scale to multiple hosts/time ranges:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wineventlog" SourceName="Backup Agent" (EventCode="1000" OR EventCode="1001") 
| transaction maxspan=4h startswith=(EventCode="1000") endswith=(EventCode="1001") 
| table host,duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Mar 2016 19:10:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252724#M189351</guid>
      <dc:creator>dw385</dc:creator>
      <dc:date>2016-03-18T19:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating Different Events and Calculating Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252725#M189352</link>
      <description>&lt;P&gt;Try this first:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="wineventlog" SourceName="Backup Agent" (EventCode="1000" OR EventCode="1001") 
 | transaction host maxspan=4h startswith=(EventCode="1000") endswith=(EventCode="1001") 
 | table host,duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All I did was add &lt;CODE&gt;host&lt;/CODE&gt; to the transaction command. This should help, but it still may not be a good solution, if you have a long time range.&lt;BR /&gt;
You could also try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="wineventlog" SourceName="Backup Agent" (EventCode="1000" OR EventCode="1001") 
| sort host,_time
| eval starttime=if(EventCode="1000",_time,null())
| eval endtime=if(EventCode="1001",_time,null())
| streamstats current=t window=2 global=f latest(starttime) as start latest(endtime) as end by host
| where isnotnull(endtime)
| eval duration=end-start
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This solution should work with somewhat larger timeframes. I am not sure how well it will work if you have multiple backups for a single host.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 21:33:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252725#M189352</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-03-18T21:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating Different Events and Calculating Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252726#M189353</link>
      <description>&lt;P&gt;How many times these events can happen from one host in a day?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 21:34:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252726#M189353</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-18T21:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating Different Events and Calculating Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252727#M189354</link>
      <description>&lt;P&gt;Usually only one occurrence but its possible to see multiple in a day as jobs are restarted.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 12:04:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-Different-Events-and-Calculating-Time-Difference/m-p/252727#M189354</guid>
      <dc:creator>dw385</dc:creator>
      <dc:date>2016-03-21T12:04:19Z</dc:date>
    </item>
  </channel>
</rss>

