<?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: Correct syntax of eval string case in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Correct-syntax-of-eval-string-case/m-p/654021#M226008</link>
    <description>&lt;P&gt;A small tip:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval "Severity Level"=split("1,2,3,4", ",") 
| mvexpand "Severity Level" &lt;/LI-CODE&gt;&lt;P&gt;Can also be created like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=4
| streamstats count as "Severity Level"&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 11 Aug 2023 07:48:04 GMT</pubDate>
    <dc:creator>jotne</dc:creator>
    <dc:date>2023-08-11T07:48:04Z</dc:date>
    <item>
      <title>Correct syntax of eval string case</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correct-syntax-of-eval-string-case/m-p/654012#M226006</link>
      <description>&lt;P&gt;I have a "Severity Level" field in both index A and index B.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Their structure is like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;==index A===
Severity Level
1
2
3
4

===index B===
Severity Level
critical
high
medium
low&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Now I want to combine the two indexes in a search and display the Severity Level using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| timechart count by "Severity Level"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where the combined "Severity Level" values only contain 1,2,3,4&lt;/P&gt;&lt;P&gt;So, I need an eval = case() to map them.&lt;/P&gt;&lt;P&gt;My syntax for for that is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;eval "Severity Level" = case('Severity Level' == "critical", 1 ,'Severity Level' == "high", 2, 'Severity Level' == "medium", 3, 'Severity Level' == "low", 4, 'Severity Level' == 1, 1, 'Severity Level'  == 2, 2, 'Severity Level'  == 3, 3, 'Severity Level'  == 4, 4, 1=1, null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;By this, the result gives incorrect result, i.e., only showing incorrect counts on 4. I think the problem is in the single and double quote, but I am not sure which is which. It is a bit urgent so I need help. Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 05:14:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correct-syntax-of-eval-string-case/m-p/654012#M226006</guid>
      <dc:creator>itnewbie</dc:creator>
      <dc:date>2023-08-11T05:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Correct syntax of eval string case</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correct-syntax-of-eval-string-case/m-p/654014#M226007</link>
      <description>&lt;P&gt;There doesn't appear to be anything functionally wrong with the case. With eval, you MUST use single quotes to wrap field names on the RIGHT hand side of the eval, whereas double quotes are used on the LEFT hand side, i.e.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval "Severity Level" = case('Severity Level'...)&lt;/LI-CODE&gt;&lt;P&gt;As you have&lt;/P&gt;&lt;P&gt;This shows your eval is correct&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval "Severity Level"=split("1,2,3,4", ",") 
| mvexpand "Severity Level" 
| append 
    [| makeresults 
    | eval "Severity Level"=split("critical,high,medium,low", ",") 
    | mvexpand "Severity Level"
        ] 
| fields - _time 
| eval "Severity Level" = case('Severity Level' == "critical", 1 ,'Severity Level' == "high", 2, 'Severity Level' == "medium", 3, 'Severity Level' == "low", 4, 'Severity Level' == 1, 1, 'Severity Level' == 2, 2, 'Severity Level' == 3, 3, 'Severity Level' == 4, 4, 1=1, null)&lt;/LI-CODE&gt;&lt;P&gt;but you could just do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval "Severity Level" = case('Severity Level' == "critical", 1,
                               'Severity Level' == "high", 2, 
                               'Severity Level' == "medium", 3, 
                               'Severity Level' == "low", 4, 1==1, 'Severity Level')&lt;/LI-CODE&gt;&lt;P&gt;as the final case statement is just saying that it will take the value of Severity Level - unless you may have some other value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 05:57:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correct-syntax-of-eval-string-case/m-p/654014#M226007</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-08-11T05:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Correct syntax of eval string case</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correct-syntax-of-eval-string-case/m-p/654021#M226008</link>
      <description>&lt;P&gt;A small tip:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval "Severity Level"=split("1,2,3,4", ",") 
| mvexpand "Severity Level" &lt;/LI-CODE&gt;&lt;P&gt;Can also be created like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=4
| streamstats count as "Severity Level"&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 11 Aug 2023 07:48:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correct-syntax-of-eval-string-case/m-p/654021#M226008</guid>
      <dc:creator>jotne</dc:creator>
      <dc:date>2023-08-11T07:48:04Z</dc:date>
    </item>
  </channel>
</rss>

