<?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: Working with boolean operations like an arithmetic operation. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363225#M107285</link>
    <description>&lt;P&gt;Hi @bangalorep, thank your for your reply and your time. &lt;/P&gt;

&lt;P&gt;What I really want is to use &lt;A href="https://plato.stanford.edu/entries/boolalg-math/"&gt;boolean math&lt;/A&gt; in Splunk. I represented the function like Splunk did, for example: &lt;/P&gt;

&lt;P&gt;A OR B in boolean maths is (A + B) but 1 + 1 is not 2, 1 + 1 in boolean maths is 1&lt;BR /&gt;
A AND B in boolean maths is (A*B), in this case any value multiply by 0 is always 0. &lt;/P&gt;

&lt;P&gt;but if I want to represent the function: &lt;/P&gt;

&lt;P&gt;A = 1&lt;BR /&gt;
B = 1&lt;BR /&gt;
C = 1&lt;BR /&gt;
D = 1&lt;/P&gt;

&lt;P&gt;F = (A * B) * (C + D)  or in Splunk syntax&lt;/P&gt;

&lt;P&gt;F = (A AND B) AND (C OR D) &lt;/P&gt;

&lt;P&gt;I cannot do it in Splunk. If I do it like arithmetic operators I will have:&lt;/P&gt;

&lt;P&gt;F = (1 * 1) * ( 1 + 1) = 2 &lt;/P&gt;

&lt;P&gt;But I want the boolean math, I only want a result like 0 or 1, nothing else: &lt;/P&gt;

&lt;P&gt;F = (1 * 1) * (1 + 1) = 1 or&lt;BR /&gt;
F = (1 AND 1) AND (1 OR 1) = 1&lt;/P&gt;

&lt;P&gt;Yes, I know I can use the where syntax but I want to make boolean operations in Splunk like I do a single arithmetic operation.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Mar 2018 11:41:00 GMT</pubDate>
    <dc:creator>jrballesteros05</dc:creator>
    <dc:date>2018-03-20T11:41:00Z</dc:date>
    <item>
      <title>Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363220#M107280</link>
      <description>&lt;P&gt;Hello Everyone, I've just done a Splunk query that it required a lot of conditionals and I just wanted to use &lt;A href="https://en.wikipedia.org/wiki/Boolean_algebra"&gt;boolean&lt;/A&gt; algebra to solve it but when I wanted to apply in Splunk I had many problems.&lt;/P&gt;

&lt;P&gt;For example I have the value A and the value B, all of those values are booleans and the operation I want to do is F=A AND −B (Negated B value).&lt;/P&gt;

&lt;P&gt;So if A=0 and B=0, the operation will be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;F = 0 AND 1 
F= 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If A=1 AND B=0 then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;F = 1 AND 1
F= 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I will have 4 combinations and I only want results where F=0, at the moment  I can solve it with this query in Splunk: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval A = 1
| eval B = 1
| eval NOTB = if(B=0,1,0)
| eval F =  if( A = 1 AND NOTB=0,1,0)
| where F = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is OK for now because I only have 4 combinations of values but I will have much more combinations in the future and I'd rather use something like this if I could: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval A = 1
| eval B = 1
| eval NOTB = if(B=0,1,0)
| eval F = A AND NOTB
| where F = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The error I get when I tried to do that is: &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Error in 'eval' command: Typechecking failed. 'AND' only takes boolean arguments.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Any help will be appreciate.&lt;/P&gt;

&lt;P&gt;Best regards.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 09:40:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363220#M107280</guid>
      <dc:creator>jrballesteros05</dc:creator>
      <dc:date>2018-03-19T09:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363221#M107281</link>
      <description>&lt;P&gt;Hello! Can you please provide sample data?&lt;BR /&gt;
Also, what inputs are A and B, that you'll be getting more than 4 combinations?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 08:24:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363221#M107281</guid>
      <dc:creator>bangalorep</dc:creator>
      <dc:date>2018-03-20T08:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363222#M107282</link>
      <description>&lt;P&gt;Hi @bangalorep. This is the macro query I did. A AND B will be a result from other conditions, but it always be a boolean value, in my case I use 0 AND 1 but it can be TRUE OR FALSE.  This is the complete query I used.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;inputlookup cve-vul-alienvault-lookup-usa
| eval CurrentCycle="20180201"
| eval cycle_detection_time=strptime(CurrentCycle,"%Y%m%d")
| eval Cycle1monthago = strftime(relative_time(cycle_detection_time,"@month-1month"),"%Y%m%d")
| where cycle_detection = CurrentCycle OR cycle_detection=Cycle1monthago
| eval A = if(Auth = "AuthOK" AND cycle_detection=Cycle1monthago,1,0)
| eval B = if((Auth = "AuthOK" OR Auth="NULL") AND cycle_detection=CurrentCycle,1,0)
| eventstats sum(A) as A , sum(B) as B, count by id,dest_ip
| eval F = if(A=1 AND B=0,1,0)
| where F=0
| eval IsResolved = case ((count = 2 AND cycle_detection=CurrentCycle),"Not Resolved",(count=1 AND cycle_detection=Cycle1monthago),"Resolved", count=1 AND cycle_detection=CurrentCycle,"New Vulnerability")
| fields id,dest_ip,cycle_detection,os,signature,type,cvss,cve,Resultados,IsResolved
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is now solved with they query I have because I only have 4 combinations of values between A AND B. &lt;/P&gt;

&lt;P&gt;A = 0 AND B = 0&lt;BR /&gt;
A = 0 AND B = 1&lt;BR /&gt;
A = 1 AND B = 0&lt;BR /&gt;
A = 1 AND B = 1&lt;/P&gt;

&lt;P&gt;I want the result of all combinations except when A = 1 AND B = 0 so I decided to call the result as F, F will be 1 if I want to ignore the result and 0 if I want to keep it so I will have something like this: &lt;/P&gt;

&lt;P&gt;A = 0 AND B = 0 so F = 0&lt;BR /&gt;
A = 0 AND B = 1 so F = 0&lt;BR /&gt;
A = 1 AND B = 0 so F = 1&lt;BR /&gt;
A = 1 AND B = 1 so F = 0&lt;/P&gt;

&lt;P&gt;The mathematical functions which represents what I wanted is: &lt;STRONG&gt;F = (A AND BNEGATED)&lt;/STRONG&gt; this is the same logic we use in electronic circuits. So if I receive these values in the results: &lt;/P&gt;

&lt;P&gt;A = 1 AND B = 1&lt;/P&gt;

&lt;P&gt;Then BNEGATED = 0 so F = (1 AND 0 ) then F = 0 &lt;/P&gt;

&lt;P&gt;if I received these values&lt;/P&gt;

&lt;P&gt;A = 1 AND B = 0&lt;/P&gt;

&lt;P&gt;Then BNEGATED = 1 so F = (1 AND 1) then F = 1 &lt;/P&gt;

&lt;P&gt;There are two ways (Maybe more but I don't know and I'll be able to receive any recommendation) I can solve this problem, the fist one is like the previous query: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval F = if(A=1 AND B=0,1,0)
| where F=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That logic is OK because I only have two variables to compare and I only have 4 combinations available but I really want to use the boolean function like logic circuits in electronic components. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval NEGATEDB = if(B=0,1,0)
| eval F = A AND NEGATEDB
| where F=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Why I want to work this way? Because in this case I only have 2 variables (A and B) and only 4 combinations but in the future I'm planning to have 4 variables (maybe more)  and then I will have 16 combinations of values so I don't want to use a case, I think a function is the best way (I might be wrong). For example in the case with 3 variables I have this function: &lt;/P&gt;

&lt;P&gt;F = B AND C AND ( A OR ANEGATED)&lt;/P&gt;

&lt;P&gt;so when A = 1, B = 0, C= 1 I will have: &lt;/P&gt;

&lt;P&gt;F = 0 AND 1 AND (1 OR 0) = 0 AND 1 AND 1 = 0 . This is going to be OK&lt;/P&gt;

&lt;P&gt;if A = 1, B = 1, C =0 I will have: &lt;/P&gt;

&lt;P&gt;F = 1 AND 1 AND (1 OR 0) = 1 AND 1 AND 1 = 1. Splunk will filter this value because I want results when F=0&lt;/P&gt;

&lt;P&gt;In short words I want to work with Boolean values like arithmetic values: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval V = X/t 
where V &amp;gt;= 100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;At the moment I don't know how to or if it's possible. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;I hope I did not confused anyone hehehe&lt;/STRONG&gt; and I also did not focus in A and B values, the A and B values will always be 0 or 1. Those values come from other conditionals but will be 1 or 0. &lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 10:33:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363222#M107282</guid>
      <dc:creator>jrballesteros05</dc:creator>
      <dc:date>2018-03-20T10:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363223#M107283</link>
      <description>&lt;P&gt;So, what i understand is, you are going to have 4 variables (A,B,C and D) and you wantthe results for F=0 where F = A AND B AND C AND D.&lt;/P&gt;

&lt;P&gt;could you maybe run a search like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where (A=1 OR B=1 OR C=1 OR D=1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;instead of searching for &lt;CODE&gt;F=0&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval A = 1 
| eval B = 0 
| eval C= 0 
| eval D=1 
| eval F=if(A==0 OR B==0 OR C==0 OR D==0,0,1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 10:59:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363223#M107283</guid>
      <dc:creator>bangalorep</dc:creator>
      <dc:date>2018-03-20T10:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363224#M107284</link>
      <description>&lt;P&gt;If you represent your boolean values as 1 and 0, you could also apply normal arithmetic operators, to calculate the result, right?&lt;/P&gt;

&lt;P&gt;Especially with an AND that is easy, as it can be implemented with multiplication and the negation can be implemented as &lt;CODE&gt;abs(B-1)&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval A = 1 
| eval B = 0
| eval F = A * abs(B-1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 11:29:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363224#M107284</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-03-20T11:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363225#M107285</link>
      <description>&lt;P&gt;Hi @bangalorep, thank your for your reply and your time. &lt;/P&gt;

&lt;P&gt;What I really want is to use &lt;A href="https://plato.stanford.edu/entries/boolalg-math/"&gt;boolean math&lt;/A&gt; in Splunk. I represented the function like Splunk did, for example: &lt;/P&gt;

&lt;P&gt;A OR B in boolean maths is (A + B) but 1 + 1 is not 2, 1 + 1 in boolean maths is 1&lt;BR /&gt;
A AND B in boolean maths is (A*B), in this case any value multiply by 0 is always 0. &lt;/P&gt;

&lt;P&gt;but if I want to represent the function: &lt;/P&gt;

&lt;P&gt;A = 1&lt;BR /&gt;
B = 1&lt;BR /&gt;
C = 1&lt;BR /&gt;
D = 1&lt;/P&gt;

&lt;P&gt;F = (A * B) * (C + D)  or in Splunk syntax&lt;/P&gt;

&lt;P&gt;F = (A AND B) AND (C OR D) &lt;/P&gt;

&lt;P&gt;I cannot do it in Splunk. If I do it like arithmetic operators I will have:&lt;/P&gt;

&lt;P&gt;F = (1 * 1) * ( 1 + 1) = 2 &lt;/P&gt;

&lt;P&gt;But I want the boolean math, I only want a result like 0 or 1, nothing else: &lt;/P&gt;

&lt;P&gt;F = (1 * 1) * (1 + 1) = 1 or&lt;BR /&gt;
F = (1 AND 1) AND (1 OR 1) = 1&lt;/P&gt;

&lt;P&gt;Yes, I know I can use the where syntax but I want to make boolean operations in Splunk like I do a single arithmetic operation.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 11:41:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363225#M107285</guid>
      <dc:creator>jrballesteros05</dc:creator>
      <dc:date>2018-03-20T11:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363226#M107286</link>
      <description>&lt;P&gt;Hello @FrankVI. This is closer for what I want. &lt;/P&gt;

&lt;P&gt;The AND is OK, how can implement the OR and the XOR. If I can implement only the OR it will be ok because I can simulate the XOR with AND's and OR's. &lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 11:43:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363226#M107286</guid>
      <dc:creator>jrballesteros05</dc:creator>
      <dc:date>2018-03-20T11:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363227#M107287</link>
      <description>&lt;P&gt;OR would be addition, where you need to translate any result &lt;CODE&gt;&amp;gt;1&lt;/CODE&gt; to &lt;CODE&gt;1&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval A = 1
| eval B = 0
| eval F = min(1,A+B)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;XOR can be done with subtraction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval A = 1
| eval B = 0
| eval F = abs(A-B)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 12:42:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363227#M107287</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-03-20T12:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Working with boolean operations like an arithmetic operation.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363228#M107288</link>
      <description>&lt;P&gt;Hello @FrankVl, this is exactly what I need. Thank you so much for your reply and your time. &lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 16:39:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-boolean-operations-like-an-arithmetic-operation/m-p/363228#M107288</guid>
      <dc:creator>jrballesteros05</dc:creator>
      <dc:date>2018-03-21T16:39:29Z</dc:date>
    </item>
  </channel>
</rss>

