<?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: Finding time difference between 2 events with different states in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-difference-between-2-events-with-different-states/m-p/540701#M152998</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/230904"&gt;@KaitoKozo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In simple scenarios with a relatively small number of events, the transaction command works well enough:&lt;/P&gt;&lt;P&gt;| transaction asset startswith=eval(switch_state==1) endswith=eval(switch_state==-1)&lt;BR /&gt;| table _time asset duration&lt;BR /&gt;| fieldformat duration=tostring(duration, "duration")&lt;/P&gt;</description>
    <pubDate>Sun, 21 Feb 2021 06:04:14 GMT</pubDate>
    <dc:creator>tscroggins</dc:creator>
    <dc:date>2021-02-21T06:04:14Z</dc:date>
    <item>
      <title>Finding time difference between 2 events with different states</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-difference-between-2-events-with-different-states/m-p/538383#M152190</link>
      <description>&lt;P&gt;I am trying to find the time difference between 2 events with different states, in particular when the device turns on or off. However, I only have the field of status which shows that it's on (1) or off (0).&lt;/P&gt;&lt;P&gt;I made use of the delta function to derive whether the device is turning on (1), turning off (-1) or no change in state (0) as state as follows:&lt;BR /&gt;| delta status p=1 as switch_state&lt;/P&gt;&lt;P&gt;I would like to know the operation hours of the device (time difference between switch_state=-1 and switch_state=1) but am unsure how to do a comparison.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My previous attempt was to use the streamstats function to compute, however I could only compare between same states as follows:&lt;BR /&gt;&lt;BR /&gt;| streamstats count(eval(switch_state=-1)&amp;nbsp; AS startcount by asset&lt;BR /&gt;| stats range(_time)&amp;nbsp; AS duration by startcount asset&lt;/P&gt;&lt;P&gt;Hoping to try to change the code or use a different method to compare between states -1 and 1 within the same field and then find the time difference between them.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 07:32:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-difference-between-2-events-with-different-states/m-p/538383#M152190</guid>
      <dc:creator>KaitoKozo</dc:creator>
      <dc:date>2021-02-03T07:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Finding time difference between 2 events with different states</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-time-difference-between-2-events-with-different-states/m-p/540701#M152998</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/230904"&gt;@KaitoKozo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In simple scenarios with a relatively small number of events, the transaction command works well enough:&lt;/P&gt;&lt;P&gt;| transaction asset startswith=eval(switch_state==1) endswith=eval(switch_state==-1)&lt;BR /&gt;| table _time asset duration&lt;BR /&gt;| fieldformat duration=tostring(duration, "duration")&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 06:04:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-time-difference-between-2-events-with-different-states/m-p/540701#M152998</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2021-02-21T06:04:14Z</dc:date>
    </item>
  </channel>
</rss>

