<?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: multivalue in a sub search not working as expected. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335015#M99559</link>
    <description>&lt;P&gt;Thanks for your response and sorry for not being clear. Below is what I am trying to acheive.&lt;/P&gt;

&lt;P&gt;1) for rock_status between 200 and 599, I am counting as TOTAL requests received on the server. this also includes 404's if the server is out. &lt;/P&gt;

&lt;P&gt;2) In another field (server_status), I am trying to see if the server is out of rotation by checking the log file for   "livelive.test" for 404's with  and mark the the server_status field value as OUT and if  "livelive.test" is 200's, I update the server_status field value with 200.. for corresponding server. &lt;/P&gt;

&lt;P&gt;apologize for not being clear earlier.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 17:11:31 GMT</pubDate>
    <dc:creator>sukundur</dc:creator>
    <dc:date>2020-09-29T17:11:31Z</dc:date>
    <item>
      <title>multivalue in a sub search not working as expected.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335013#M99557</link>
      <description>&lt;P&gt;I am trying to return  multi value from a subsearch  and use that value in a field (server_status) as "OUT" in the main search and rest as "IN".  Instead, it displaying all the values as IN. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=*  sourcetype="rock:access" "/status/*"  | stats count(eval(rock_status&amp;gt;=200 AND rock_status&amp;lt;=599)) AS TOTAL by host | eval  server_status=if(rock_status=404,[search index=* host=server*  sourcetype="rock:access" "*/livelive.test"  | search rock_status=404 | return $host ],IN) | table host,server_status, TOTAL 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to get something like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; host   server_status   total
server1     IN          64434
server2     IN          63517
server3     IN          25536
server4     IN          7090
server5     OUT         9
server6     OUT         2
server7     OUT         7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;can you please help.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;We marked code and data as code to ease reading.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 15:35:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335013#M99557</guid>
      <dc:creator>sukundur</dc:creator>
      <dc:date>2017-12-09T15:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: multivalue in a sub search not working as expected.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335014#M99558</link>
      <description>&lt;P&gt;Ok, I am going to try to untangle this, because the structure of your search has left me somewhat confused. Let me see if I understand your intention:&lt;/P&gt;

&lt;P&gt;You have some events with &lt;CODE&gt;sourcetype="rock:access"&lt;/CODE&gt;. Each of those events contains a field called &lt;CODE&gt;host&lt;/CODE&gt; and another field called &lt;CODE&gt;rock_status&lt;/CODE&gt;. You want to count the number of events for each host that match some criteria and also, based on those criteria, create a field called &lt;CODE&gt;server_status&lt;/CODE&gt;. It appears to me that if an event contains &lt;CODE&gt;"/status/"&lt;/CODE&gt; and the field &lt;CODE&gt;rock_status&lt;/CODE&gt; is between 200 and 599 (inclusive) then you want the field &lt;CODE&gt;server_status&lt;/CODE&gt; to be &lt;CODE&gt;IN&lt;/CODE&gt;. If the event contains &lt;CODE&gt;"*/livelive.test"&lt;/CODE&gt; and the field &lt;CODE&gt;rock_status&lt;/CODE&gt; is 404, then you want the field &lt;CODE&gt;server_status&lt;/CODE&gt; to be &lt;CODE&gt;OUT&lt;/CODE&gt;. Then you want to count the number of events for each host and assign the count to a field called &lt;CODE&gt;total&lt;/CODE&gt;. Finally, you want to make a table showing &lt;CODE&gt;host&lt;/CODE&gt;, &lt;CODE&gt;server_status&lt;/CODE&gt;, and &lt;CODE&gt;total&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;If that's all correct, then I think this should do the trick for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="rock:access" "status" OR "livelive.test" rock_status=* 
| eval server_status=case
  (rock_status&amp;gt;=200 AND rock_status&amp;lt;=599 AND match(_raw, "\/status\/"), "IN", 
  rock_status=404 AND match(_raw, "\/livelive\.test"), "OUT", 
  1=1, "Not Categorized") 
| stats count AS total BY host server_status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: If &lt;CODE&gt;"/status/"&lt;/CODE&gt; and &lt;CODE&gt;"*/livelive.test"&lt;/CODE&gt; are captured in a field, it would be best to replace the instances of &lt;CODE&gt;_raw&lt;/CODE&gt; in that code with the name of the field. &lt;/P&gt;

&lt;P&gt;Please be aware that the code above does not guarantee that every host will be assigned only one &lt;CODE&gt;server_status&lt;/CODE&gt; code. If some events for a given host match the conditions for &lt;CODE&gt;IN&lt;/CODE&gt; and some match the conditions for &lt;CODE&gt;OUT&lt;/CODE&gt;, both will be reflected in the final table. I also left an optional catchall at the end of the &lt;CODE&gt;case&lt;/CODE&gt; statement to capture events that don't match the category assignments. If you want to silently discard those events, you can remove the &lt;CODE&gt;1=1, "Not Categorized"&lt;/CODE&gt; from the end of the case statement and add &lt;CODE&gt;| where isnotnull(server_status)&lt;/CODE&gt; immediately before &lt;CODE&gt;| stats count AS total BY host server_status&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;If my understanding was incorrect, please feel free to clarify, and I'll try to help again.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 19:05:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335014#M99558</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-12-10T19:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: multivalue in a sub search not working as expected.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335015#M99559</link>
      <description>&lt;P&gt;Thanks for your response and sorry for not being clear. Below is what I am trying to acheive.&lt;/P&gt;

&lt;P&gt;1) for rock_status between 200 and 599, I am counting as TOTAL requests received on the server. this also includes 404's if the server is out. &lt;/P&gt;

&lt;P&gt;2) In another field (server_status), I am trying to see if the server is out of rotation by checking the log file for   "livelive.test" for 404's with  and mark the the server_status field value as OUT and if  "livelive.test" is 200's, I update the server_status field value with 200.. for corresponding server. &lt;/P&gt;

&lt;P&gt;apologize for not being clear earlier.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:11:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335015#M99559</guid>
      <dc:creator>sukundur</dc:creator>
      <dc:date>2020-09-29T17:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: multivalue in a sub search not working as expected.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335016#M99560</link>
      <description>&lt;P&gt;So does the code above give you the correct output? If not, can you give some examples of the raw data that's being incorrectly categorized and how you'd prefer it to be categorized? I'm not totally certain what is different between what I documented/proposed and what you've said here. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 18:20:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335016#M99560</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-12-12T18:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: multivalue in a sub search not working as expected.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335017#M99561</link>
      <description>&lt;P&gt;@elliot - Looks like a good attempt.  I'd probably try to present the results on one line per server.  &lt;/P&gt;

&lt;P&gt;I believe the OP may be looking for the most recent status code being 404 to mean "out"... in which case you could get &lt;CODE&gt;latest(rock_status) as xxx&lt;/CODE&gt; when you do your &lt;CODE&gt;stats count&lt;/CODE&gt;,  and then use xxx to calculate the IN/OUT. &lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 19:54:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335017#M99561</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-12-12T19:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: multivalue in a sub search not working as expected.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335018#M99562</link>
      <description>&lt;P&gt;Thanks @dal - if you're right, then perhaps this code would work?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype="rock:access" "status" OR "livelive.test" rock_status=* 
| stats latest(rock_status) AS  server_status count AS total BY host 
| eval server_status=if(server_status=404, "OUT", "IN")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Dec 2017 21:09:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335018#M99562</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-12-12T21:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: multivalue in a sub search not working as expected.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335019#M99563</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I think you need to remake the fields multivalue after the subsearch&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval testx="test1 test3", index="1" | makemv testx | join type=outer index [ | makeresults | eval test="test1 test2", index="1" | makemv test] | makemv test
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jan 2019 16:57:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multivalue-in-a-sub-search-not-working-as-expected/m-p/335019#M99563</guid>
      <dc:creator>maraman_splunk</dc:creator>
      <dc:date>2019-01-18T16:57:49Z</dc:date>
    </item>
  </channel>
</rss>

