<?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: How to use eval within stats for data from tstats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412144#M118866</link>
    <description>&lt;P&gt;This works for me (using &lt;CODE&gt;prestats&lt;/CODE&gt; is a deep, dark magic):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats summariesonly=t allow_old_summaries=f count
FROM datamodel=Network_Traffic.All_Traffic 
WHERE (All_Traffic.action!="unknown") BY sourcetype All_Traffic.action _time span=1h 
 | rename All_Traffic.* AS *
 | stats count As total_connections count(eval(action=="allowed")) AS allowed count(eval(action=="blocked" OR action=="dropped")) AS blocked BY _time, sourcetype
| eval pct_blocked = 100 * blocked / total_connections
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 27 Jul 2019 17:24:21 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-07-27T17:24:21Z</dc:date>
    <item>
      <title>How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412141#M118863</link>
      <description>&lt;P&gt;I'm trying to use eval within stats to work with data from tstats, but it doesn't seem to work the way I expected it to work. I'm hoping there's something that I can do to make this work.&lt;/P&gt;

&lt;P&gt;Here's a simplified version of what I'm trying to do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats summariesonly=t allow_old_summaries=f prestats=t count from datamodel=Network_Traffic.All_Traffic where (All_Traffic.action!="unknown") by _time,sourcetype,All_Traffic.action span=1h 
| `drop_dm_object_name("All_Traffic")` 
| stats count as total_connections count(eval(action="allowed")) as allowed count(eval(action="blocked" OR action="dropped")) as blocked by _time, sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run that, I see valid numbers for total_connections, but the "allowed" and "blocked" values are all just "0"&lt;/P&gt;

&lt;P&gt;The following works for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats summariesonly=t allow_old_summaries=f prestats=f count from datamodel=Network_Traffic.All_Traffic where (All_Traffic.action!="unknown") by _time,sourcetype,All_Traffic.action span=1h 
| `drop_dm_object_name("All_Traffic")`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, that doesn't present the data in the way I want it. I'd like to add things like percentage blocked per sourcetype, etc., with additional eval statements.&lt;/P&gt;

&lt;P&gt;Any suggestions for how to get the stats command to work with those nested eval statements? Is that unsupported? (I've read that nested eval within tstats isn't supported, but that it is supported within stats)&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 19:38:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412141#M118863</guid>
      <dc:creator>kcheek_umich</dc:creator>
      <dc:date>2019-07-23T19:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412142#M118864</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try without the prestats option (it works as desired for me):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats summariesonly=t allow_old_summaries=f count from datamodel=Network_Traffic.All_Traffic where (All_Traffic.action!="unknown") by _time,sourcetype,All_Traffic.action span=1h 
| `drop_dm_object_name("All_Traffic")` 
| stats count as total_connections count(eval(action="allowed")) as allowed count(eval(action="blocked" OR action="dropped")) as blocked by _time, sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="https://imgur.com/PcGQlQ8" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Hope it helps&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 23:43:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412142#M118864</guid>
      <dc:creator>jaime_ramirez</dc:creator>
      <dc:date>2019-07-23T23:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412143#M118865</link>
      <description>&lt;P&gt;While that does produce numbers in more of the fields, they aren't correct numbers when I try that. Instead of counting the number of network traffic events, stats just counts the number of distinct values of "action" per sourcetype that match each eval statement. (so, in my case, the calculated values from the stats command are all 0, 1, 2, or 3)&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 19:05:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412143#M118865</guid>
      <dc:creator>kcheek_umich</dc:creator>
      <dc:date>2019-07-24T19:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412144#M118866</link>
      <description>&lt;P&gt;This works for me (using &lt;CODE&gt;prestats&lt;/CODE&gt; is a deep, dark magic):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats summariesonly=t allow_old_summaries=f count
FROM datamodel=Network_Traffic.All_Traffic 
WHERE (All_Traffic.action!="unknown") BY sourcetype All_Traffic.action _time span=1h 
 | rename All_Traffic.* AS *
 | stats count As total_connections count(eval(action=="allowed")) AS allowed count(eval(action=="blocked" OR action=="dropped")) AS blocked BY _time, sourcetype
| eval pct_blocked = 100 * blocked / total_connections
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 17:24:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412144#M118866</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-27T17:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412145#M118867</link>
      <description>&lt;P&gt;For me, this has the same result as the suggestion from jaime.ramirez - I don't get counts of network events. Instead, I get what appears to be the count of unique values for "action" for each "stats eval" for each sourcetype (0, 1, 2, or 3).&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 14:23:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412145#M118867</guid>
      <dc:creator>kcheek_umich</dc:creator>
      <dc:date>2019-07-29T14:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412146#M118868</link>
      <description>&lt;P&gt;You do see the &lt;CODE&gt;total_connections&lt;/CODE&gt; field, right?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 18:05:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412146#M118868</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-29T18:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412147#M118869</link>
      <description>&lt;P&gt;Yep - and it only has the values 0, 1, 2, or 3 - it doesn't actually contain the total number of connections unless I use prestats=t&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 18:12:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412147#M118869</guid>
      <dc:creator>kcheek_umich</dc:creator>
      <dc:date>2019-07-29T18:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412148#M118870</link>
      <description>&lt;P&gt;OK, I finally get it.  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats summariesonly=t allow_old_summaries=f count
FROM datamodel=Network_Traffic.All_Traffic 
WHERE index=* BY sourcetype All_Traffic.action _time span=1h 
| rename All_Traffic.* AS * 
| stats count As total_connections count(eval(action=="allowed")) AS allowed count(eval(action=="blocked" OR action=="dropped")) AS blocked BY _time, sourcetype 
| eval pct_blocked = 100 * blocked / total_connections
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 18:54:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/412148#M118870</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-29T18:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval within stats for data from tstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/616223#M214174</link>
      <description>&lt;P&gt;The trick is to use "case" eval function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;count(eval(action="allowed")) as allowed count(eval(action="blocked" OR action="dropped")) as blocked

values(eval(case(action="allowed", count))) as allowed values(eval(case(action="blocked" OR action="dropped", count))) as blocked&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 20:17:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-within-stats-for-data-from-tstats/m-p/616223#M214174</guid>
      <dc:creator>stoomart</dc:creator>
      <dc:date>2022-10-06T20:17:57Z</dc:date>
    </item>
  </channel>
</rss>

