<?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: Need help with eval and if then statement - showing errors. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431779#M123422</link>
    <description>&lt;P&gt;Maybe this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="bigfix"
[|inputlookup list.csv 
| eval search_score = if(bigfix = 1,1,0) + if(norton = 1,3,0) + if(mcafee = 1,6,0)
| where search_score==1
| rename ip AS IPAddress
| table IPAddress]
| table IPAddress, CompName, MAC , OS, Manufacturer, Model
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Feb 2019 06:23:13 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-02-12T06:23:13Z</dc:date>
    <item>
      <title>Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431771#M123414</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| inputlookup list.csv 
| eval newbigfix=if(bigfix = 1,1,0)
| eval newnorton=if(norton = 1,3,0)
| eval newmcafee=if(mcafee = 1,6,0)
| eval search_score = newbigfix  + newnorton  + newmcafee
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above search works and returns all of  the columns needed and adds the correct numbers to the columns.&lt;/P&gt;

&lt;P&gt;However, I am trying run an eval and if then statement after the above search as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup list.csv 
| eval newbigfix=if(bigfix = 1,1,0)
| eval newnorton=if(norton = 1,3,0)
| eval newmcafee=if(mcafee = 1,6,0)
| eval search_score = newbigfix  + newnorton  + newmcafee
| eval search1 = if (search_score == 1, [search index="bigfix" IPAddress ="198.168.1.25" | table IPAddress, CompName, MAC , OS, Manufacturer, Model], "")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above search fails with the following error:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Error in 'eval' command: Fields cannot&lt;BR /&gt;
be assigned a boolean result. Instead,&lt;BR /&gt;
try if([bool expr], [expr], [expr]).&lt;BR /&gt;
The search job has failed due to an&lt;BR /&gt;
error. You may be able view the job in&lt;BR /&gt;
the Job Inspector.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;If I run just the search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|search index="bigfix" IPAddress ="198.168.1.25" | table IPAddress, CompName, MAC , OS, Manufacturer, Model
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It runs just fine.&lt;/P&gt;

&lt;P&gt;Any ideas why the | eval search1 = if is not working?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 17:38:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431771#M123414</guid>
      <dc:creator>UMDTERPS</dc:creator>
      <dc:date>2019-01-29T17:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431772#M123415</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| where index="bigfix" IPAddress ="198.168.1.25" | table IPAddress, CompName, MAC , OS, Manufacturer, Model&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 18:55:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431772#M123415</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-01-31T18:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431773#M123416</link>
      <description>&lt;P&gt;Try this:&lt;BR /&gt;
    | makeresults | eval bigfix=1 | eval norton=1 | eval mcafee=0 &lt;BR /&gt;
    | eval newbigfix=if(bigfix = 1,1,0)&lt;BR /&gt;
    | eval newnorton=if(norton = 1,3,0)&lt;BR /&gt;
    | eval newmcafee=if(mcafee = 1,6,0)&lt;BR /&gt;
    | eval search_score = newbigfix  + newnorton  + newmcafee&lt;BR /&gt;
    | eval search1 = if (search_score == 4, "index=bigfix IPAddress =198.168.1.25 | table IPAddress CompName MAC  OS Manufacturer Model","")&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:03:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431773#M123416</guid>
      <dc:creator>vishaltaneja070</dc:creator>
      <dc:date>2020-09-29T23:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431774#M123417</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;

&lt;P&gt;For this search we are using a lookuptable (CSV), so  | inputlookup list.csv needs to be there.&lt;/P&gt;

&lt;P&gt;For further clarification the eval statement below:&lt;/P&gt;

&lt;P&gt;| inputlookup list.csv &lt;BR /&gt;
| eval newbigfix=if(bigfix = 1,1,0)&lt;BR /&gt;
| eval newnorton=if(norton = 1,3,0)&lt;BR /&gt;
| eval newmcafee=if(mcafee = 1,6,0)&lt;BR /&gt;
| eval search_score = newbigfix + newnorton + newmcafee&lt;BR /&gt;
adds&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval newbigfix=if(bigfix = 1,1,0)&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;What this statement is saying is that if the ip has a 1 in the bigfix field we assign it a 1, if it doesn't -it assigns it a 0 (because it doesn't have big fix).  The number it gets assigned goes into the "newbigfix" field.&lt;/P&gt;

&lt;P&gt;The above is that same for all 3 eval statements.  Once the "New" score is assigned for a given IP, I do an eval to add up all of the numbers and place the number in a new field called "search score":&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval search_score = newbigfix + newnorton + newmcafee
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In order to return the correct fields, I use another eval statement "search1" to return fields based on the "search_score"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval search1 = if (search_score == 1, [search index="bigfix" IPAddress ="198.168.1.25" | table IPAddress, CompName, MAC , OS, Manufacturer, Model], "")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:07:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431774#M123417</guid>
      <dc:creator>UMDTERPS</dc:creator>
      <dc:date>2019-02-01T14:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431775#M123418</link>
      <description>&lt;P&gt;Give me a mockup of what you expect &lt;CODE&gt;search1&lt;/CODE&gt; to contain at the end.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 17:39:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431775#M123418</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-01T17:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431776#M123419</link>
      <description>&lt;P&gt;We have 4 fields in the | inputlookup list.csv as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ip                 bigfix       norton      mcafee 
198.168.1.25       1          0                 0

1. | inputlookup list.csv 
2. | eval newbigfix=if(bigfix = 1,1,0)
3. | eval newnorton=if(norton = 1,3,0)
4. | eval newmcafee=if(mcafee = 1,6,0)
5. | eval search_score = newbigfix + newnorton + newmcafee
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The if then eval statements looks at the fields to see if there is a 0 or 1 in each of the agent fields and then creates a new column called “search_score” by adding all of the numbers agent field numbers together and assigns a score:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ip                bigfix        norton      mcafee     search_score
198.168.1.25       1           0                      0     1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For example, in the case of 198.168.1.25, the if than statement sees that there is a 1 for bigfix and a 0 for norton and mcafee. The final eval statement will add all of the scores together and assign a score.  In this case, because 198.168.1.25 only has a 1 for bigfix and 0 for norton and mcafee, it will be assigned a 1 for the newly created "search_score" field.  &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt; | eval search1 = if (search_score == 1, [search index="bigfix" IPAddress ="198.168.1.25" | table IPAddress, CompName, MAC , OS, Manufacturer, Model], "")&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;In regards to your question, “search1" looks to see which ips have a search score equal to 1, because we know that having a search_score equal to 1 can only mean the ip has a 1 for big fix.  search1 will return the following fields from bigfix- IPAddress, CompName, MAC , OS, Manufacturer, Model. If the ip has a search_score of 4, we know the ip has bigfix and norton, search1 will return fields from bigfix and norton. I chose just to use bigfix in search1 as an example to make it less complicated to explain for help.&lt;/P&gt;

&lt;P&gt;Does that help in better understanding of what search 1 is suppose to do?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:09:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431776#M123419</guid>
      <dc:creator>UMDTERPS</dc:creator>
      <dc:date>2020-09-29T23:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431777#M123420</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Error in 'makeresults' command: This&lt;BR /&gt;
command must be the first command of a&lt;BR /&gt;
search. The search job has failed due&lt;BR /&gt;
to an error. You may be able view the&lt;BR /&gt;
job in the Job Inspector.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 06 Feb 2019 15:48:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431777#M123420</guid>
      <dc:creator>UMDTERPS</dc:creator>
      <dc:date>2019-02-06T15:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431778#M123421</link>
      <description>&lt;P&gt;I know that you are trying but it still makes absolutely no sense to me at all.  Let's go back around again.  Show me 5 lines of what the output is after the &lt;CODE&gt;| eval search_score = newbigfix + newnortn + newmcafee&lt;/CODE&gt; line executes.  Then DO NOT SHOW ANY MORE SPL.  Just show me how you would like those 5 lines transformed for your final result.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 20:05:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431778#M123421</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-08T20:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with eval and if then statement - showing errors.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431779#M123422</link>
      <description>&lt;P&gt;Maybe this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="bigfix"
[|inputlookup list.csv 
| eval search_score = if(bigfix = 1,1,0) + if(norton = 1,3,0) + if(mcafee = 1,6,0)
| where search_score==1
| rename ip AS IPAddress
| table IPAddress]
| table IPAddress, CompName, MAC , OS, Manufacturer, Model
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Feb 2019 06:23:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-with-eval-and-if-then-statement-showing-errors/m-p/431779#M123422</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-12T06:23:13Z</dc:date>
    </item>
  </channel>
</rss>

