<?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 Combining results in a search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462822#M130510</link>
    <description>&lt;P&gt;I have a search that graphs the number of events based on host name.  It even colour codes into Windows and Linux hosts.  The search goes like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="main" OR index="win*")
| stats count as total by host,index
| eval host=lower(host) 
| sort host 
| eval Linux = if(index=="main",total, 0) 
| eval Windows = if((index == "windows") or (index == "wineventlog"), total, 0) 
| fields host Linux Windows
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works exactly as expected except in the scenario when a host reports via two different indexes.  When this occurs, the host is shown twice.  Once for each index.&lt;/P&gt;

&lt;P&gt;For example, host server1 has data indexed to Windows and to WinEventLog so two enteries appear for server1 (one for each index).&lt;/P&gt;

&lt;P&gt;My question is, how can I get the search to combine the counts into a single entry so that I only see each host once.&lt;/P&gt;

&lt;P&gt;I've tried something like &lt;CODE&gt;"| eval Windows = if(index like "win%", total, 0)"&lt;/CODE&gt; but that does not give the desired result.&lt;/P&gt;

&lt;P&gt;Any suggestions greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2019 22:52:06 GMT</pubDate>
    <dc:creator>balcv</dc:creator>
    <dc:date>2019-12-16T22:52:06Z</dc:date>
    <item>
      <title>Combining results in a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462822#M130510</link>
      <description>&lt;P&gt;I have a search that graphs the number of events based on host name.  It even colour codes into Windows and Linux hosts.  The search goes like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="main" OR index="win*")
| stats count as total by host,index
| eval host=lower(host) 
| sort host 
| eval Linux = if(index=="main",total, 0) 
| eval Windows = if((index == "windows") or (index == "wineventlog"), total, 0) 
| fields host Linux Windows
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works exactly as expected except in the scenario when a host reports via two different indexes.  When this occurs, the host is shown twice.  Once for each index.&lt;/P&gt;

&lt;P&gt;For example, host server1 has data indexed to Windows and to WinEventLog so two enteries appear for server1 (one for each index).&lt;/P&gt;

&lt;P&gt;My question is, how can I get the search to combine the counts into a single entry so that I only see each host once.&lt;/P&gt;

&lt;P&gt;I've tried something like &lt;CODE&gt;"| eval Windows = if(index like "win%", total, 0)"&lt;/CODE&gt; but that does not give the desired result.&lt;/P&gt;

&lt;P&gt;Any suggestions greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 22:52:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462822#M130510</guid>
      <dc:creator>balcv</dc:creator>
      <dc:date>2019-12-16T22:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Combining results in a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462823#M130511</link>
      <description>&lt;P&gt;After line 6, add a  &lt;CODE&gt;| stats sum(Linux) as Linux, sum(Windows) as Windows by host&lt;/CODE&gt;. This should take all of the numeric values for all indexes post-characterization of Linux or Windows and sum them by host. &lt;/P&gt;

&lt;P&gt;The alternative is to put your two &lt;CODE&gt;eval&lt;/CODE&gt; statements first, and then using the same command I showed above in place of your &lt;CODE&gt;stats&lt;/CODE&gt; command, but that option might be slightly more expensive. You can try them both and assuming they return the same values, pick whichever one returns faster!&lt;/P&gt;

&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 00:21:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462823#M130511</guid>
      <dc:creator>aberkow</dc:creator>
      <dc:date>2019-12-17T00:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Combining results in a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462824#M130512</link>
      <description>&lt;P&gt;The reason &lt;CODE&gt;eval&lt;/CODE&gt; won't work to combine two rows is that it's a streaming command &lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.0/Search/Typesofcommands#Streaming_and_non-streaming_commands"&gt;https://docs.splunk.com/Documentation/Splunk/8.0.0/Search/Typesofcommands#Streaming_and_non-streaming_commands&lt;/A&gt; and works on an event level, while &lt;CODE&gt;stats&lt;/CODE&gt;, which I suggest below, is a transforming command (transforms after all rows are indexed and can do aggregations like you're interested in doing).&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 00:22:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462824#M130512</guid>
      <dc:creator>aberkow</dc:creator>
      <dc:date>2019-12-17T00:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Combining results in a search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462825#M130513</link>
      <description>&lt;P&gt;That did the trick.  Thank you @aberkow&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 01:03:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-results-in-a-search/m-p/462825#M130513</guid>
      <dc:creator>balcv</dc:creator>
      <dc:date>2019-12-17T01:03:02Z</dc:date>
    </item>
  </channel>
</rss>

