<?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 Looping if condition in for loop and display different tables in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245550#M73185</link>
    <description>&lt;P&gt;I have a table with 10 records. 2 rows for each host - say AUX0001 to AUX0005. For each host, 2 processes occur: the status and time range. AUX0001 disp.exe abcded green running , AUX0001 wxze.exe red running. In this way it is present for all the hosts.. &lt;BR /&gt;
My requirement - if both processes are green, host should display only once for disp.exe. if both are red, then both processes should be displayed. If one is green and one is red , it should be red with that process name be it disp.exe or wxze.exe.   This looks simple. but unable to achieve this. &lt;/P&gt;

&lt;P&gt;I tried several ways - Should i have to loop for each host? I'm not getting the desired result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="xxx" sourcetype="yy" |fields name description dispstatus textstatus starttime elapsedtime pid source|eval host_source = mvindex(split(source,"\\"),5)|eventstats count(eval(dispstatus="Green")) as green_count  count(eval(dispstatus="Red")) as red_count by host_source|eval desc_test = case(green_count ==2 OR red_count ==2,"Dispatcher", red_count ==1 AND description="watchdog" ,"watch", red_count ==1 AND description=" Dispatcher " ," Dispatcher ")|table host_source description dispstatus desc_test|where description=desc_test 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can someone please help me here? Thanks a lot&lt;/P&gt;</description>
    <pubDate>Sun, 22 Jan 2017 03:52:36 GMT</pubDate>
    <dc:creator>k_harini</dc:creator>
    <dc:date>2017-01-22T03:52:36Z</dc:date>
    <item>
      <title>Looping if condition in for loop and display different tables</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245550#M73185</link>
      <description>&lt;P&gt;I have a table with 10 records. 2 rows for each host - say AUX0001 to AUX0005. For each host, 2 processes occur: the status and time range. AUX0001 disp.exe abcded green running , AUX0001 wxze.exe red running. In this way it is present for all the hosts.. &lt;BR /&gt;
My requirement - if both processes are green, host should display only once for disp.exe. if both are red, then both processes should be displayed. If one is green and one is red , it should be red with that process name be it disp.exe or wxze.exe.   This looks simple. but unable to achieve this. &lt;/P&gt;

&lt;P&gt;I tried several ways - Should i have to loop for each host? I'm not getting the desired result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="xxx" sourcetype="yy" |fields name description dispstatus textstatus starttime elapsedtime pid source|eval host_source = mvindex(split(source,"\\"),5)|eventstats count(eval(dispstatus="Green")) as green_count  count(eval(dispstatus="Red")) as red_count by host_source|eval desc_test = case(green_count ==2 OR red_count ==2,"Dispatcher", red_count ==1 AND description="watchdog" ,"watch", red_count ==1 AND description=" Dispatcher " ," Dispatcher ")|table host_source description dispstatus desc_test|where description=desc_test 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can someone please help me here? Thanks a lot&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2017 03:52:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245550#M73185</guid>
      <dc:creator>k_harini</dc:creator>
      <dc:date>2017-01-22T03:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looping if condition in for loop and display different tables</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245551#M73186</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;STATUS           DISPLAY     
DISP   WATCH     DISP   WATCH   
GREEN  GREEN     GREEN 
GREEN  RED              RED
RED    GREEN     RED   
RED    RED       RED    RED
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;okay, if either process is red, then that process should display.  On the other hand, if both processes are green, then DISP should show green.&lt;/P&gt;

&lt;P&gt;Try this for test code - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="xxx" sourcetype="yy" 
| fields name description dispstatus textstatus starttime elapsedtime pid source
| eval host_source = mvindex(split(source,"\\"),5)
| eventstats count(eval(dispstatus="Green")) as green_count by host_source
| eval desc_test = If( (dispstatus="Red") OR (green_count==2 AND description=" Dispatcher "),"Pass","Block")
| table host_source description dispstatus desc_test
| sort 0 host_source description
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If those results seem right, then use this for the actual code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="xxx" sourcetype="yy" 
| fields name description dispstatus textstatus starttime elapsedtime pid source
| eval host_source = mvindex(split(source,"\\"),5)
| eventstats count(eval(dispstatus="Green")) as green_count by host_source
| search (dispstatus="Red") OR (green_count==2 AND description=" Dispatcher ")
| table host_source description dispstatus
| sort 0 host_source description
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Jan 2017 04:27:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245551#M73186</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-22T04:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Looping if condition in for loop and display different tables</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245552#M73187</link>
      <description>&lt;P&gt;Thanks so much for your response.. I tried this.. it worked.. instead of green_count = 2 , I gave dispstatus = green, 1 green process also got displayed along with red ones.. Thanks a lot.. I got confused.. &lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2017 10:31:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245552#M73187</guid>
      <dc:creator>k_harini</dc:creator>
      <dc:date>2017-01-22T10:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Looping if condition in for loop and display different tables</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245553#M73188</link>
      <description>&lt;P&gt;You're welcome.  &lt;/P&gt;

&lt;P&gt;The little results chart I made helped me simplify the question.  There was only one condition that ever showed green (green==2), so from there it was easy.   &lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 14:49:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-if-condition-in-for-loop-and-display-different-tables/m-p/245553#M73188</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-23T14:49:37Z</dc:date>
    </item>
  </channel>
</rss>

