<?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 How to trigger an alert if the condition remains for a certain period of time? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628686#M14681</link>
    <description>&lt;P&gt;I am trying to create an alert when the field &lt;STRONG&gt;toState&lt;/STRONG&gt;&amp;nbsp;changes to &lt;STRONG&gt;OPEN&lt;/STRONG&gt;&amp;nbsp;and stays in that &lt;STRONG&gt;OPEN&lt;/STRONG&gt; state for &lt;U&gt;5 minutes&lt;/U&gt;. I have tried the following but it is not working. Would appreciate if I get some pointers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... CB_STATE_TRANSITION | timechart span=5m count(toState="OPEN") as state | stats count | where count &amp;gt; 1&lt;/LI-CODE&gt;&lt;P&gt;I have the alert run every 5 minutes and&amp;nbsp;&lt;SPAN&gt;triggers when the number of results &amp;gt; 0.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2023 21:47:07 GMT</pubDate>
    <dc:creator>splunking1</dc:creator>
    <dc:date>2023-01-27T21:47:07Z</dc:date>
    <item>
      <title>How to trigger an alert if the condition remains for a certain period of time?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628686#M14681</link>
      <description>&lt;P&gt;I am trying to create an alert when the field &lt;STRONG&gt;toState&lt;/STRONG&gt;&amp;nbsp;changes to &lt;STRONG&gt;OPEN&lt;/STRONG&gt;&amp;nbsp;and stays in that &lt;STRONG&gt;OPEN&lt;/STRONG&gt; state for &lt;U&gt;5 minutes&lt;/U&gt;. I have tried the following but it is not working. Would appreciate if I get some pointers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... CB_STATE_TRANSITION | timechart span=5m count(toState="OPEN") as state | stats count | where count &amp;gt; 1&lt;/LI-CODE&gt;&lt;P&gt;I have the alert run every 5 minutes and&amp;nbsp;&lt;SPAN&gt;triggers when the number of results &amp;gt; 0.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 21:47:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628686#M14681</guid>
      <dc:creator>splunking1</dc:creator>
      <dc:date>2023-01-27T21:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger an alert if the condition remains for a certain period of time?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628692#M14682</link>
      <description>&lt;P&gt;Perhaps this will help.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... CB_STATE_TRANSITION 
``` Get the most recent time and state ```
| stats latest(_time) as _time, latest(toState) as toState
``` Keep only the "OPEN" events with a timestamp at least 5 minutes old ```
| where (toState="OPEN" AND _time &amp;lt; relative_time(now(), "-5m")&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 28 Jan 2023 01:12:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628692#M14682</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-01-28T01:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger an alert if the condition remains for a certain period of time?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628762#M14686</link>
      <description>&lt;P&gt;I appreciate the reply. I am curious about the issue with my approach. Conceptually, it makes sense. What is the problem with that approach? Just trying to understand.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 18:15:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628762#M14686</guid>
      <dc:creator>splunking1</dc:creator>
      <dc:date>2023-01-29T18:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger an alert if the condition remains for a certain period of time?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628765#M14687</link>
      <description>&lt;P&gt;You said your query was "not working" without qualification so I offered a query that should work.&lt;/P&gt;&lt;P&gt;Let's take a closer look at the original query.&amp;nbsp; The &lt;FONT face="courier new,courier"&gt;transaction&lt;/FONT&gt; command counts the number of "OPEN" events in each 5-minute period of the search time window.&amp;nbsp; Depending the time window chosen, this will produce one or more results.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| timechart span=5m count(toState="OPEN") as state&lt;/LI-CODE&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;_time&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;state&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;01/29/2023 14:30&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;01/29/2023 14:35&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;01/29/2023 14:40&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt; command then counts the number of results produced by &lt;FONT face="courier new,courier"&gt;timechart&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats count | where count &amp;gt; 1&lt;/LI-CODE&gt;&lt;P&gt;Giving us "3", which is greater than 1.&amp;nbsp; That will erroneously trigger an alert.&lt;/P&gt;&lt;P&gt;Let's say we run the query over the previous 5 minutes with known "OPEN" events.&amp;nbsp; The &lt;FONT face="courier new, courier"&gt;timechart&amp;nbsp;&lt;/FONT&gt;command might produce something like this&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;_time&lt;/TD&gt;&lt;TD width="50%"&gt;state&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;01/29/2023 14:45&lt;/TD&gt;&lt;TD width="50%"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This time the &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt; command will return "1", which is not greater than 1 and so the alert will erroneously NOT trigger.&lt;/P&gt;&lt;P&gt;Like a broken clock, the query will occasionally work, but the false positives and false negatives make it unreliable.&lt;/P&gt;&lt;P&gt;The query could be improved by removing the stats command.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... CB_STATE_TRANSITION | timechart span=5m count(toState="OPEN") as state | where count &amp;gt; 1&lt;/LI-CODE&gt;&lt;P&gt;This will give us only the 5-minute periods where an "OPEN" event occurred and the alert can be triggered if there are results.&amp;nbsp; That doesn't mean, however, that the "OPEN" was present for all 5 of those minutes.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 19:57:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628765#M14687</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-01-29T19:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger an alert if the condition remains for a certain period of time?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628929#M14688</link>
      <description>&lt;P&gt;That makes a lot of sense. Thank you so much. One final question: If I were to extend your query to different host; would it still work?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;....CB_STATE_TRANSITION | stats latest(_time) as _time, latest(toState) as toState by host | where (toState="OPEN" AND _time &amp;lt; relative_time(now(), "-5m"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have different hosts and it is possible that the alert does not trigger for one of them even though the state was set to open for the last 5 minutes due to the state transitioning to closed. That would be a false positive so I want to account for each host separately. I will accept your answer once this thread is closed so don't worry &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 02:38:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628929#M14688</guid>
      <dc:creator>splunking1</dc:creator>
      <dc:date>2023-01-31T02:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger an alert if the condition remains for a certain period of time?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628987#M14689</link>
      <description>&lt;P&gt;Yes, adding "by host" should work as you expect.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 13:43:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-trigger-an-alert-if-the-condition-remains-for-a-certain/m-p/628987#M14689</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-01-31T13:43:55Z</dc:date>
    </item>
  </channel>
</rss>

