<?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: timechart with WHERE clause not behaving as expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456213#M128986</link>
    <description>&lt;P&gt;The &lt;CODE&gt;count&lt;/CODE&gt; and &lt;CODE&gt;user&lt;/CODE&gt; fields get turned into a matrix such that the field &lt;CODE&gt;count&lt;/CODE&gt; is absorbed.  You need to bring it back, filter on it, then, go back to where you were; try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foobar EventCode=1234
| timechart span=1d count BY user usenull=f
| untable _time user count
| eventstats max(count) AS max_count BY user
| where max_count&amp;gt;10
| timechart span=1d avg(count) AS count BY user usenull=f
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 06 Jul 2019 21:30:46 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-07-06T21:30:46Z</dc:date>
    <item>
      <title>timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456207#M128980</link>
      <description>&lt;P&gt;I have a fairly straightforward query using timechart to count the top 10 users triggering an event.  ( Sanitized ) &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;index=foobar EventCode=1234  | timechart span=1d count(EventCode) BY user WHERE max in top10 usenull=f useother=f&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;This returns a chart that makes good sense. Now in order to separate noise from things II'm concerned about, I want to only see users who have triggered the event 10 times or more per day. A quick look at the manual provided this : &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Chart the eventypes by source_ip&lt;BR /&gt;
For each minute, count the eventypes by source_ip, where the count is greater than 10.&lt;/P&gt;

&lt;H2&gt;&lt;EM&gt;sshd failed OR failure | timechart span=1m count(eventtype) BY source_ip usenull=f WHERE count&amp;gt;10&lt;/EM&gt; &lt;/H2&gt;

&lt;P&gt;(docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Timechart)&lt;/P&gt;

&lt;P&gt;So I adapted this to my existing query : &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;index=foobar EventCode=1234  | timechart span =1d count(EventCode) by user usenull=f WHERE count&amp;gt;10&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;This however did NOT generate what I expected. I expected to see the same chart as before, only with the users with less than 10 events triggered per day being left out. Instead I have a bizarre chart that I received a truncation warning for and that included users that had fewer than 10 per day. &lt;/P&gt;

&lt;P&gt;I've been told I need to put spaces in the WHERE clause ( WHERE count &amp;gt;10 , or WHERE count &amp;gt; 10 ) but this made no change. &lt;BR /&gt;
I've been told that the chart is accurate and that it reflects users who have hit more than 10 at any time ( not per day ) but that did not make sense to me, nor did it jibe with what the manual said. &lt;/P&gt;

&lt;P&gt;After many tries to make timechart work, I gave up and explored other options , and discovered this solution in a community article : &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;index=foobar EventCode=1234 | bucket span=1d _time | stats count by _time user | where count &amp;gt; 10 | xyseries _time,user,count&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;This did return what I was looking for , but I'm not sure why one works and the other doesn't.&lt;/P&gt;

&lt;P&gt;Any suggestions as to why? &lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:10:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456207#M128980</guid>
      <dc:creator>fclsplunk</dc:creator>
      <dc:date>2020-09-30T01:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456208#M128981</link>
      <description>&lt;P&gt;Have you tried using a simple count in your timechart command, instead of count(EventCode)? Results should be the same anyway, since you already filter for a certain EventCode in your base search so each event will have that field populated.&lt;/P&gt;

&lt;P&gt;Edit: when I read the docs correctly, using &lt;CODE&gt;where count &amp;gt; 10&lt;/CODE&gt; like this, actually applies over the whole period, it doesn't apply the filter for each timespan. So if the sum of the event count over all days is &amp;gt; 10, it will include that entry, even if single days are all below 10.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 09:35:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456208#M128981</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-04T09:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456209#M128982</link>
      <description>&lt;P&gt;Thanks for the reply. I tried it with COUNT instead of COUNT(EventCode) and as you indicated the results were the same. &lt;/P&gt;

&lt;P&gt;I'm not sure what you meant by " when I read the docs correctly". Which docs are you referring to , and where do they indicate that the results are the sum is over all days and not per span? &lt;/P&gt;

&lt;P&gt;What I had read ( under Basic Examples , in the on line docs for 7.3.0 )  was : &lt;/P&gt;

&lt;P&gt;"&lt;EM&gt;For each minute&lt;/EM&gt;, count the eventypes by source_ip, where the count is greater than 10." &lt;/P&gt;

&lt;P&gt;This satisfies my need for the count to be by each span , and not over all time specified. The only difference is that I used "span=1d" instead of 1 minute. &lt;/P&gt;

&lt;P&gt;Are you suggesting that there is an error in the docs, or did I miss something / am I looking in the wrong place?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 17:25:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456209#M128982</guid>
      <dc:creator>fclsplunk</dc:creator>
      <dc:date>2019-07-04T17:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456210#M128983</link>
      <description>&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Timechart#Where_clause_examples"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Timechart#Where_clause_examples&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;"Example 4: Using the where clause with the count function measures the total number of events over the period. This yields results similar to using the sum function."&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 06:20:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456210#M128983</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-05T06:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456211#M128984</link>
      <description>&lt;P&gt;OK this makes sense to me now. &lt;/P&gt;

&lt;P&gt;So all in all, is TIMECHART the wrong approach to what I'm trying to do? &lt;/P&gt;

&lt;P&gt;My goal is to chart all users who have tripped a specific alarm , per day, over 30 days  and then a second chart that shows the same information, but only for users who have tripped the alarm more than 10 times in a day. &lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 15:11:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456211#M128984</guid>
      <dc:creator>fclsplunk</dc:creator>
      <dc:date>2019-07-05T15:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456212#M128985</link>
      <description>&lt;P&gt;I guess so. Although you could still do &lt;CODE&gt;| timechart span=1d sum(count) as count by user&lt;/CODE&gt; instead of your xyseries. But you'll have to do some steps before to filter against that threshold indeed.&lt;/P&gt;

&lt;P&gt;And that also makes sense if you look at what the output of &lt;CODE&gt;timechart&lt;/CODE&gt; is. It gets you a _time column and then 1 column for each user (in contrast to a stats count by user, which gets you a count and a user column). What you want to then do is remove individual cells from that result. I guess in theory you could do that by following the &lt;CODE&gt;timechart&lt;/CODE&gt; with a &lt;CODE&gt;foreach&lt;/CODE&gt; construct to set any cell below the threshold to 0. But doing a stats first, filter that and then do the charting is probably easier.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 15:27:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456212#M128985</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-05T15:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456213#M128986</link>
      <description>&lt;P&gt;The &lt;CODE&gt;count&lt;/CODE&gt; and &lt;CODE&gt;user&lt;/CODE&gt; fields get turned into a matrix such that the field &lt;CODE&gt;count&lt;/CODE&gt; is absorbed.  You need to bring it back, filter on it, then, go back to where you were; try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foobar EventCode=1234
| timechart span=1d count BY user usenull=f
| untable _time user count
| eventstats max(count) AS max_count BY user
| where max_count&amp;gt;10
| timechart span=1d avg(count) AS count BY user usenull=f
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Jul 2019 21:30:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456213#M128986</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-06T21:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456214#M128987</link>
      <description>&lt;P&gt;I gave this a try, unfortunately it still displayed users with less than 10 events on a daily basis. &lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 20:38:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456214#M128987</guid>
      <dc:creator>fclsplunk</dc:creator>
      <dc:date>2019-07-19T20:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: timechart with WHERE clause not behaving as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456215#M128988</link>
      <description>&lt;P&gt;It depends on what you mean; if the original answer isn't it, then maybe you mean this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foobar EventCode=1234
| timechart span=1d count BY user usenull=f
| untable _time user count
| where count&amp;gt;10
| timechart span=1d avg(count) AS count BY user usenull=f
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 22:58:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-with-WHERE-clause-not-behaving-as-expected/m-p/456215#M128988</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-19T22:58:12Z</dc:date>
    </item>
  </channel>
</rss>

