<?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: use streamstats for checking multiple column values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450821#M166790</link>
    <description>&lt;P&gt;The following is a self contained example, so people can quickly try this in their own instance of Splunk. Everything up to and including the table command generates the test data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=11 
| streamstats count as row 
| eval now = relative_time(now(),"-1m@m")
| eval _time = now - ( row * 60 ) 
| eval a = IF ( (row &amp;gt;= 1 and row &amp;lt;= 3) or (row &amp;gt;= 5 and row &amp;lt;= 8) or (row &amp;gt;= 10 and row &amp;lt;= 11), 1, 0 )
| eval b = IF ( (row &amp;gt;= 2 and row &amp;lt;= 3) or (row == 5) or (row == 10), 1, 0 ) 
| eval c = IF ( (row &amp;gt;= 4 and row &amp;lt;= 5) or (row == 9) , 1, 0 ) 
| eval d = IF ( (row == 2) or (row == 7) or (row == 10), 1, 0 ) 
| table _time, a, b, c, d 
| streamstats count as count_a by a reset_on_change=true 
| streamstats count as count_b by b reset_on_change=true 
| streamstats count as count_c by c reset_on_change=true 
| streamstats count as count_d by d reset_on_change=true 
| where (a==0 and count_a &amp;gt;= 4) or (b==0 and count_b &amp;gt;= 4) or (c==0 and count_c &amp;gt;= 4) or (d==0 and count_d &amp;gt;= 4)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will return one or more rows if there are 4 or more continuous 0 matches across any of the columns (a,b,c,d). An assumption is made that a new record appears on the minute. If you want a specific alert for each column you may want to consider running several queries instead of one.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Nov 2018 11:08:38 GMT</pubDate>
    <dc:creator>msivill_splunk</dc:creator>
    <dc:date>2018-11-15T11:08:38Z</dc:date>
    <item>
      <title>use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450817#M166786</link>
      <description>&lt;P&gt;How can I use streamstats for checking multiple column values.(With or without foreach command for multiple columns)&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 13:40:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450817#M166786</guid>
      <dc:creator>sahil237888</dc:creator>
      <dc:date>2018-10-31T13:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450818#M166787</link>
      <description>&lt;P&gt;Could you pad out the question with some examples of incoming event data and expected outcomes?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 08:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450818#M166787</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-11-01T08:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450819#M166788</link>
      <description>&lt;P&gt;Hey msivill,&lt;/P&gt;

&lt;P&gt;Basically the requirement is :&lt;/P&gt;

&lt;P&gt;_time                   A   B   C   D&lt;BR /&gt;
2018-11-14 07:56:00 1   0   0   0&lt;BR /&gt;
2018-11-14 07:57:00 1   1   0   1&lt;BR /&gt;
2018-11-14 07:58:00 1   1   0   0&lt;BR /&gt;
2018-11-14 07:59:00 0   0   1   0&lt;BR /&gt;
2018-11-14 08:00:00 1   1   1   0&lt;BR /&gt;
2018-11-14 08:01:00 1   0   0   0&lt;BR /&gt;
2018-11-14 08:02:00 1   0   0   1&lt;BR /&gt;
2018-11-14 08:03:00 1   0   0   0&lt;BR /&gt;
2018-11-14 08:04:00 0   0   1   0&lt;BR /&gt;
2018-11-14 08:05:00 1   1   0   1&lt;BR /&gt;
2018-11-14 08:06:00 1   0   0   0&lt;/P&gt;

&lt;P&gt;streamstats to check for each column (A,B,C,D) and if there is continuous 0  for any column for 4 minutes, it should alert.&lt;/P&gt;

&lt;P&gt;As in the above output for B column (between 08:01 - 08:04) and for D (between 07:58 - 08:01) we have continuous 0 so alert should be triggered that B and D column has issue.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 14:17:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450819#M166788</guid>
      <dc:creator>sahil237888</dc:creator>
      <dc:date>2018-11-14T14:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450820#M166789</link>
      <description>&lt;P&gt;_time               A   B   C   D&lt;BR /&gt;
2018-11-14 07:56:00 1   0   0   0&lt;BR /&gt;
2018-11-14 07:57:00 1   1   0   1&lt;BR /&gt;
2018-11-14 07:58:00 1   1   0   0&lt;BR /&gt;
2018-11-14 07:59:00 0   0   1   0&lt;BR /&gt;
2018-11-14 08:00:00 1   1   1   0&lt;BR /&gt;
2018-11-14 08:01:00 1   0   0   0&lt;BR /&gt;
2018-11-14 08:02:00 1   0   0   1&lt;BR /&gt;
2018-11-14 08:03:00 1   0   0   0&lt;BR /&gt;
2018-11-14 08:04:00 0   0   1   0&lt;BR /&gt;
2018-11-14 08:05:00 1   1   0   1&lt;BR /&gt;
2018-11-14 08:06:00 1   0   0   0&lt;/P&gt;

&lt;P&gt;Streamstats to check for each column (A,B,C,D) and if there is continuous 0 for any column for 4 minutes, it should alert.&lt;/P&gt;

&lt;P&gt;As in the above output B have 0 (between 08:01 and 08:04) and for D (between 07:58 - 08:01) there is continuous 0 so the alert should have B and D have continuous 0&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 16:16:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450820#M166789</guid>
      <dc:creator>sahil237888</dc:creator>
      <dc:date>2018-11-14T16:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450821#M166790</link>
      <description>&lt;P&gt;The following is a self contained example, so people can quickly try this in their own instance of Splunk. Everything up to and including the table command generates the test data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=11 
| streamstats count as row 
| eval now = relative_time(now(),"-1m@m")
| eval _time = now - ( row * 60 ) 
| eval a = IF ( (row &amp;gt;= 1 and row &amp;lt;= 3) or (row &amp;gt;= 5 and row &amp;lt;= 8) or (row &amp;gt;= 10 and row &amp;lt;= 11), 1, 0 )
| eval b = IF ( (row &amp;gt;= 2 and row &amp;lt;= 3) or (row == 5) or (row == 10), 1, 0 ) 
| eval c = IF ( (row &amp;gt;= 4 and row &amp;lt;= 5) or (row == 9) , 1, 0 ) 
| eval d = IF ( (row == 2) or (row == 7) or (row == 10), 1, 0 ) 
| table _time, a, b, c, d 
| streamstats count as count_a by a reset_on_change=true 
| streamstats count as count_b by b reset_on_change=true 
| streamstats count as count_c by c reset_on_change=true 
| streamstats count as count_d by d reset_on_change=true 
| where (a==0 and count_a &amp;gt;= 4) or (b==0 and count_b &amp;gt;= 4) or (c==0 and count_c &amp;gt;= 4) or (d==0 and count_d &amp;gt;= 4)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will return one or more rows if there are 4 or more continuous 0 matches across any of the columns (a,b,c,d). An assumption is made that a new record appears on the minute. If you want a specific alert for each column you may want to consider running several queries instead of one.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 11:08:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450821#M166790</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-11-15T11:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450822#M166791</link>
      <description>&lt;P&gt;A time based one....&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=11 
| streamstats count as row 
| eval now = relative_time(now(),"-1m@m")
| eval _time = now - ( row * 60 ) 
| eval a = IF ( (row &amp;gt;= 1 and row &amp;lt;= 3) or (row &amp;gt;= 5 and row &amp;lt;= 8) or (row &amp;gt;= 10 and row &amp;lt;= 11), 1, 0 )
| eval b = IF ( (row &amp;gt;= 2 and row &amp;lt;= 3) or (row == 5) or (row == 10), 1, 0 ) 
| eval c = IF ( (row &amp;gt;= 4 and row &amp;lt;= 5) or (row == 9) , 1, 0 ) 
| eval d = IF ( (row == 2) or (row == 7) or (row == 10), 1, 0 ) 
| table _time, a, b, c, d 
| streamstats first(_time) as time_a_first, last(_time) as time_a_last by a reset_on_change=true
| streamstats first(_time) as time_b_first, last(_time) as time_b_last by b reset_on_change=true
| streamstats first(_time) as time_c_first, last(_time) as time_c_last by c reset_on_change=true
| streamstats first(_time) as time_d_first, last(_time) as time_d_last by d reset_on_change=true
| eval time_a_duration = time_a_first - time_a_last 
| eval time_b_duration = time_b_first - time_b_last 
| eval time_c_duration = time_c_first - time_c_last 
| eval time_d_duration = time_d_first - time_d_last 
| where (a==0 and time_a_duration &amp;gt;= 180) or (b==0 and time_b_duration &amp;gt;= 180) or (c==0 and time_c_duration &amp;gt;= 180) or (d==0 and time_d_duration &amp;gt;= 180) 
| stats max(time_a_duration) as a, max(time_b_duration) as b, max(time_c_duration) as c, max(time_d_duration) as d
| untable row indicator duration 
| table indicator duration
| where duration &amp;gt;= 180
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Nov 2018 11:51:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450822#M166791</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-11-15T11:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450823#M166792</link>
      <description>&lt;P&gt;This seems to be somewhat working for rows but the result should be based on columns.&lt;BR /&gt;
and there are multiple columns (say more than 10) so its difficult to create too many eval conditions if we have multiple columns.&lt;BR /&gt;
Will it be possible to use foreach and streamstats in this.&lt;BR /&gt;
like below :&lt;/P&gt;

&lt;P&gt;| streamstats window=5 sum(column_&lt;EM&gt;) as newcolumn_&lt;/EM&gt; reset_before="("column_*"&amp;lt;0)"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:03:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450823#M166792</guid>
      <dc:creator>sahil237888</dc:creator>
      <dc:date>2020-09-29T22:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450824#M166793</link>
      <description>&lt;P&gt;This seems to be somewhat working for rows but the result should be based on columns.&lt;BR /&gt;
and there are multiple columns (say more than 10) so its difficult to create too many eval conditions if we have multiple columns.&lt;BR /&gt;
Will it be possible to use foreach and streamstats in this.&lt;BR /&gt;
like below :&lt;/P&gt;

&lt;P&gt;| streamstats window=5 sum(column_&lt;EM&gt;) as newcolumn_&lt;/EM&gt; reset_before="("column_*"&amp;lt;0)"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:03:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450824#M166793</guid>
      <dc:creator>sahil237888</dc:creator>
      <dc:date>2020-09-29T22:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450825#M166794</link>
      <description>&lt;P&gt;If it is for only ten columns I would expand out the above example. Not sure its difficult (just repetitive) as there is a pattern in the SPL that needs to be repeated.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 12:39:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450825#M166794</guid>
      <dc:creator>msivill_splunk</dc:creator>
      <dc:date>2018-11-15T12:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: use streamstats for checking multiple column values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450826#M166795</link>
      <description>&lt;P&gt;There are more than 10 columns so thats why I was guessing to use foreach.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 12:57:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-streamstats-for-checking-multiple-column-values/m-p/450826#M166795</guid>
      <dc:creator>sahil237888</dc:creator>
      <dc:date>2018-11-15T12:57:51Z</dc:date>
    </item>
  </channel>
</rss>

