<?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: Not counting events in between event pairs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335094#M99582</link>
    <description>&lt;P&gt;All the results disappear when the second half of line 12 is added.  Since CurrState is defined as TransactionCode=DOPN, doesn't it automatically exclude events where the code might be PWPL?&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2017 21:47:50 GMT</pubDate>
    <dc:creator>ellenbytech</dc:creator>
    <dc:date>2017-07-27T21:47:50Z</dc:date>
    <item>
      <title>Not counting events in between event pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335089#M99577</link>
      <description>&lt;P&gt;My search is &lt;BR /&gt;
&lt;CODE&gt;index=safes TransactionCode=DOPN OR TransactionCode=PWPL Details="*opened" OR Details="AC*" &lt;BR /&gt;
| transaction open_ACpwr startswith=DOPN endswith=PWPL maxevents=2 | search eventcount=2&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Essentially I want a list of events where someone opens a door and then encounters a power loss.  This search, however is just pairing the last time the door was opened and the next power loss, whether or not the door was shut before the power loss occurred.&lt;BR /&gt;
Would another way to do this be to pair every AC power loss event with the event immediately preceding it and then filtering out the ones that are not door open events? How would I go about doing this?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 14:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335089#M99577</guid>
      <dc:creator>ellenbytech</dc:creator>
      <dc:date>2017-07-27T14:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Not counting events in between event pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335090#M99578</link>
      <description>&lt;P&gt;You can include maxpause option in your transaction command to incorporate 'immediate' constraint. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=safes (TransactionCode=DOPN  Details="*opened") OR (TransactionCode=PWPLDetails="AC*") | transaction open_ACpwr startswith=DOPN endswith=PWPL maxevents=2 maxpause=2s | search eventcount=2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2017 16:00:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335090#M99578</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-27T16:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Not counting events in between event pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335091#M99579</link>
      <description>&lt;P&gt;Ok, that seems to clear up that issue but now I'm getting results from different locations as one event.  For example: &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Store# 935: Door opened 12:01:01&lt;BR /&gt;
gets paired with&lt;BR /&gt;
Store#2805: AC power loss 12:01:03&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Can I restrict this further without running separate searches on every single store?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 20:57:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335091#M99579</guid>
      <dc:creator>ellenbytech</dc:creator>
      <dc:date>2017-07-27T20:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Not counting events in between event pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335092#M99580</link>
      <description>&lt;P&gt;If store number is extracted as a field, add it to the transaction command along with open_ACpwr.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 21:09:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335092#M99580</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-27T21:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Not counting events in between event pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335093#M99581</link>
      <description>&lt;P&gt;Don't use transaction, use &lt;CODE&gt;streamstats&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;You want to know when a door opened and has not yet closed when you get a power outage.&lt;/P&gt;

&lt;P&gt;So, you need the &lt;CODE&gt;_time&lt;/CODE&gt; and &lt;CODE&gt;Location&lt;/CODE&gt; of every event where the door opens, every event where the door closes, and every event  where there is a power outage. (I've assumed that Door Close events are &lt;CODE&gt;TransactionCode="DCLO"&lt;/CODE&gt;.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search that gets _time, Location, and DOPN or DCLO OR PWPL

| eval DoorState=case(TransactionCode="DOPN","Open",TransactionCode="DCLO","Closed",true(),null())
| eval DoorOpenTime=if(TransactionCode="DOPN",_time,null())
| sort 0 Location _time 
| rename COMMENT as "The above sets up the state of the door and a field to remember the time it opened"

| rename COMMENT as "Now we copy forward the state of the door and track it across time."
| streamstats current=t last(DoorState) as CurrState last(DoorOpenTime) as DoorOpenTime by Location

| rename COMMENT as "Get rid of any record that isn't a power loss with an open door."
| where CurrState="Open" AND TransactionCode="PWPL"

| rename COMMENT as "Now we format the results"
| table _time Location TransactionCode CurrState DoorOpenTime
| eval DoorOpenTime=strftime(DoorOpenTime,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If there is any reason you want to see the entire event for the Door Open, then just use the same strategy with _raw that we did with &lt;CODE&gt;DoorOpenTime&lt;/CODE&gt;.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;updated to put quotes around the final filter for "PWPL"&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 21:25:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335093#M99581</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-27T21:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Not counting events in between event pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335094#M99582</link>
      <description>&lt;P&gt;All the results disappear when the second half of line 12 is added.  Since CurrState is defined as TransactionCode=DOPN, doesn't it automatically exclude events where the code might be PWPL?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 21:47:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335094#M99582</guid>
      <dc:creator>ellenbytech</dc:creator>
      <dc:date>2017-07-27T21:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Not counting events in between event pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335095#M99583</link>
      <description>&lt;P&gt;@ellenbytech - Sorry, updated to put quotes around "PWPL"&lt;/P&gt;

&lt;P&gt;In answer to your question, NO, that's what the &lt;CODE&gt;streamstats&lt;/CODE&gt; is tasked to do... copy the last open/closed status from the same location forward onto each record.  Since a &lt;CODE&gt;PWPL&lt;/CODE&gt; record has no status of its own, it gets the one from the immediate prior record of either an open or close type.   &lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 23:58:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-counting-events-in-between-event-pairs/m-p/335095#M99583</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-27T23:58:35Z</dc:date>
    </item>
  </channel>
</rss>

