<?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: Conditional-ish Sums in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81746#M20729</link>
    <description>&lt;P&gt;It is not a bug but a function of the original requirements:  The 'inbytes' calculation depends on the value of 'dir'.  This is just one way to express that in the search language.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Nov 2010 11:06:45 GMT</pubDate>
    <dc:creator>bwooden</dc:creator>
    <dc:date>2010-11-04T11:06:45Z</dc:date>
    <item>
      <title>Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81740#M20723</link>
      <description>&lt;P&gt;This is killing me.&lt;/P&gt;

&lt;P&gt;I'm trying to sum the bytes crossing my boundary in each direction.  For TCP sessions, I have a field of "dir" which indicates whether the TCP session is established from the outside-to-the-inside or from the inside-to-the-outside.  &lt;/P&gt;

&lt;P&gt;For example, dir=outb means that the client is internal and the server is external.&lt;BR /&gt;
Obversely, dir=inb means that the client is external and the server is internal.&lt;/P&gt;

&lt;P&gt;Now, I also have fields "client_bytes" and "server_bytes" which represent the number of bytes transmitted FROM the client or server, respectively.&lt;/P&gt;

&lt;P&gt;So, I want to create "outbytes" and "inbytes".&lt;/P&gt;

&lt;P&gt;Inbytes="sum(client_bytes) when dir=inb"   PLUS   "sum(server_bytes) when dir=outb"&lt;/P&gt;

&lt;P&gt;Outbytes="sum(client_bytes) when dir=outb"   PLUS   "sum(server_bytes) when dir=inb"&lt;/P&gt;

&lt;P&gt;So, how do I conditionally extract the value of a field (client_bytes OR server_bytes) according to another field's value (dir=inb OR dir=outb)?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2010 02:48:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81740#M20723</guid>
      <dc:creator>blurblebot</dc:creator>
      <dc:date>2010-11-02T02:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81741#M20724</link>
      <description>&lt;P&gt;Use &lt;CODE&gt;eval&lt;/CODE&gt; with &lt;CODE&gt;if&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| eval inbytes=if(dir=inb, client_bytes, server_bytes)
| eval outbytes=if(dir=outb, client_bytes, server_bytes)
| stats sum(inbytes) sum(outbytes)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See also, &lt;A href="http://www.splunk.com/base/Documentation/4.1.5/SearchReference/CommonEvalFunctions" rel="nofollow"&gt;functions for eval and where&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2010 03:18:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81741#M20724</guid>
      <dc:creator>southeringtonp</dc:creator>
      <dc:date>2010-11-02T03:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81742#M20725</link>
      <description>&lt;P&gt;I see how this works, and it makes sense given the following table:&lt;/P&gt;

&lt;P&gt;Event1) dir=inb  cb=100 sb=10  - after two passes of eval, (IB=100, OB=10)&lt;/P&gt;

&lt;P&gt;Event2) dir=outb cb=40  sb=33  - after two passes of eval, (IB=33,  OB=40) &lt;/P&gt;

&lt;P&gt;So what I'd expect for results are:&lt;/P&gt;

&lt;P&gt;sum(OB)=50 &lt;/P&gt;

&lt;P&gt;sum(IB)=133 &lt;/P&gt;

&lt;P&gt;However your suggested search gives me identical values for sum(OB) and sum(IB).&lt;/P&gt;

&lt;P&gt;So I tested this on a smaller set of data: &lt;/P&gt;

&lt;P&gt;event1) dir=inb cb=100 sb=33&lt;/P&gt;

&lt;P&gt;event2) dir=outb cb=14 sb=27&lt;/P&gt;

&lt;P&gt;...| eval ib=if(dir=inb, cb, sb)|eval ob=if(dir=outb, cb, sb) | stats sum(ib) sum(ob)&lt;/P&gt;

&lt;P&gt;and got the results:&lt;/P&gt;

&lt;P&gt;sum(ib)=60, sum(ob)=60&lt;/P&gt;

&lt;P&gt;So now I'm completely confused.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2010 04:56:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81742#M20725</guid>
      <dc:creator>blurblebot</dc:creator>
      <dc:date>2010-11-02T04:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81743#M20726</link>
      <description>&lt;P&gt;Thanks for the quick reply, but this didn't quite work.  See my answer below for explanation.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2010 04:56:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81743#M20726</guid>
      <dc:creator>blurblebot</dc:creator>
      <dc:date>2010-11-02T04:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81744#M20727</link>
      <description>&lt;P&gt;I think you want a little of each of the solutions already posted.  This search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=*input.txt | eval inbytes=if(dir="inb",cb,if(dir="outb",sb,"")) | 
eval outbytes=if(dir="outb",cb,if(dir="inb",sb,"")) | 
stats sum(inbytes) as inbytes sum(outbytes) as outbytes
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;returns this data...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;inbytes     outbytes
133     50
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where the events are...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event1) dir=inb cb=100 sb=10
Event2) dir=outb cb=40 sb=33
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Nov 2010 12:35:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81744#M20727</guid>
      <dc:creator>bwooden</dc:creator>
      <dc:date>2010-11-02T12:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81745#M20728</link>
      <description>&lt;P&gt;Thanks for the answer. I'm a little fuzzy as to why the nested eval statements are necessary.   Is this a bug?  I ask because it seems more logical that each event is supposed to be passed through each of the two eval phrases of the search in, say, southerningtonp's answer...&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2010 02:19:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81745#M20728</guid>
      <dc:creator>blurblebot</dc:creator>
      <dc:date>2010-11-04T02:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81746#M20729</link>
      <description>&lt;P&gt;It is not a bug but a function of the original requirements:  The 'inbytes' calculation depends on the value of 'dir'.  This is just one way to express that in the search language.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2010 11:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81746#M20729</guid>
      <dc:creator>bwooden</dc:creator>
      <dc:date>2010-11-04T11:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional-ish Sums</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81747#M20730</link>
      <description>&lt;P&gt;I wasn't clear.  I'm just trying to understand why nesting is necessary, when southerningtonp's answer SEEMS to make sense.  With inbytes, for instance (using his answer), I thought the eval if would assign the value of client_bytes to inbytes if dir=inb, and server_bytes if not. THEN do the same process for the eval outbytes line.  I can empirically see that it doesn't, yes, but can you help me understand why not?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:20:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-ish-Sums/m-p/81747#M20730</guid>
      <dc:creator>blurblebot</dc:creator>
      <dc:date>2020-09-28T09:20:26Z</dc:date>
    </item>
  </channel>
</rss>

