<?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 use eval to find percentage for field values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476761#M133818</link>
    <description>&lt;P&gt;I have values for a field named action, block, passed, and alerted. How would I go about creating a search to looks for the percentage of blocked to passed/alerted events?&lt;/P&gt;

&lt;P&gt;I have the basic search of&lt;BR /&gt;
    index=foo&lt;BR /&gt;
    | stats count by src, action&lt;BR /&gt;
    | stats list(action) as Action, list(count) as count, sum(count) as Total by src&lt;/P&gt;

&lt;P&gt;and was thinking eval could be used in some way&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2020 17:01:53 GMT</pubDate>
    <dc:creator>jwalzerpitt</dc:creator>
    <dc:date>2020-01-08T17:01:53Z</dc:date>
    <item>
      <title>How to use eval to find percentage for field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476761#M133818</link>
      <description>&lt;P&gt;I have values for a field named action, block, passed, and alerted. How would I go about creating a search to looks for the percentage of blocked to passed/alerted events?&lt;/P&gt;

&lt;P&gt;I have the basic search of&lt;BR /&gt;
    index=foo&lt;BR /&gt;
    | stats count by src, action&lt;BR /&gt;
    | stats list(action) as Action, list(count) as count, sum(count) as Total by src&lt;/P&gt;

&lt;P&gt;and was thinking eval could be used in some way&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 17:01:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476761#M133818</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2020-01-08T17:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to find percentage for field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476762#M133819</link>
      <description>&lt;P&gt;You're definitely on the right track - I like doing something like this for readability, as you clearly create a variable for pass and fail, and set it to a bool. Then, you can just sum them by whatever you want (I did src in this case), then do a simple divide eval command to get the percent.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo
| stats count by src, action
|eval pass=if(action="pass", 1, 0)
|eval fail=if(action="fail", 1, 0)
|stats sum(pass) as numPass, sum(fail) as numFail by src
|eval failPerc=numFail/(numFail + numPass) * 100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 18:12:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476762#M133819</guid>
      <dc:creator>aberkow</dc:creator>
      <dc:date>2020-01-08T18:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to find percentage for field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476763#M133820</link>
      <description>&lt;P&gt;Thx for the search. The issue that I'm having with the search you suggested is that the count of each action is reduced to a sum of the count which is just '1' and not the total count,. For example, I have IPs that are into the hundreds for allows, yet when I run the search they're reduced to one pass/fail.&lt;/P&gt;

&lt;P&gt;I changed the last line to &lt;CODE&gt;| stats count(pass) as numPass, count(fail) as numFail by src&lt;/CODE&gt; and the count was more than one, but way less then the true count. It's like the eval isn't being applied to every event.&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 14:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476763#M133820</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2020-01-10T14:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to find percentage for field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476764#M133821</link>
      <description>&lt;P&gt;Sample query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1000
| eval src="A.A.A.A#B.B.B.B#C.C.C.C#D.D.D.D"
| eval action="pass#fail"
| eval src=mvindex(split(src,"#"),random() % 3)
| eval action=mvindex(split(action,"#"),random() % 2)
| chart limit=0 count by src action
| eval failPerc=round(fail / ( fail + pass ) * 100,2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;recommend:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo action=fail OR action=pass
| chart limit=0 useother=f usenull=f count by src action
| eval failPerc=round(fail / ( fail + pass ) * 100,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jan 2020 19:43:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-find-percentage-for-field-values/m-p/476764#M133821</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-10T19:43:44Z</dc:date>
    </item>
  </channel>
</rss>

