<?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: group different source in one querry in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292867#M161122</link>
    <description>&lt;P&gt;I downvoted this post because prefer the first solution because it's the shorter one&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2017 07:39:14 GMT</pubDate>
    <dc:creator>bosch_softtec</dc:creator>
    <dc:date>2017-05-17T07:39:14Z</dc:date>
    <item>
      <title>group different source in one querry</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292862#M161117</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I'm running Splunk 6.6 and I like to group different sources of an Index to count them within one querry.&lt;BR /&gt;
The scenario is the following:&lt;BR /&gt;
Index: service_log&lt;BR /&gt;
sources:&lt;BR /&gt;
- serviceA_1.log&lt;BR /&gt;
- serviceA_2.log&lt;BR /&gt;
- serviceA_3.log&lt;BR /&gt;
- serviceB_1.log&lt;BR /&gt;
- serviceB_2.log&lt;BR /&gt;
- serviceC_1.log&lt;BR /&gt;
- serviceC_2.log&lt;/P&gt;

&lt;P&gt;I have three services running and spreaded over more servers, the log content is stored in one index. Now I like to count the service user grouped by the different sources and display the values with a  trellis view. With the following SPL I get the values for each source but I have no idea how I could the sources.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=service_log | dedup service_user | stats count(service_user) as Anzahl by source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The out put is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/data/log/SERVICE/A_1/service.log   830
/data/log/SERVICE/A_2/service.log   822
/data/log/SERVICE/A_3/service.log   823
/data/log/SERVICE/B_1/service.log   11
/data/log/SERVICE/B_2/service.log   9
/data/log/SERVICE/C_1/service.log   2
/data/log/SERVICE/C_2/service.log   1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I like to get something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SERVICE_A   2475
SERVICE_B   20
SERVICE_C   3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for your tips and answers.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:04:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292862#M161117</guid>
      <dc:creator>bosch_softtec</dc:creator>
      <dc:date>2020-09-29T14:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: group different source in one querry</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292863#M161118</link>
      <description>&lt;P&gt;Form your query this way -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=service_log | rex field=source "\/data\/log\/SERVICE\/(?&amp;lt;log_source&amp;gt;\w)" | eval log_source="SERVICE_".log_source | stats dc(service_user) as Anzahl by log_source
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 May 2017 09:30:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292863#M161118</guid>
      <dc:creator>dineshraj9</dc:creator>
      <dc:date>2017-05-15T09:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: group different source in one querry</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292864#M161119</link>
      <description>&lt;P&gt;Try the following. Once you have tested the sourcePattern, move the same to &lt;STRONG&gt;Knowledge Objects&lt;/STRONG&gt; as &lt;STRONG&gt;Calculated Field&lt;/STRONG&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=service_log 
| dedup service_user 
| eval sourcePattern=case(
                                                match(source,"/data/log/SERVICE/A_"),"SourceA",
                                                match(source,"/data/log/SERVICE/B_"),"SourceB",
                                                match(source,"/data/log/SERVICE/C_"),"SourceC",
                                                true(),"Unknown"
                                                )
| stats count(service_user) as Anzahl by sourcePattern
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 May 2017 10:18:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292864#M161119</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-05-15T10:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: group different source in one querry</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292865#M161120</link>
      <description>&lt;P&gt;Hi, thank you for the two solutions, they are both working perfect.&lt;BR /&gt;
Due to that I only could accept one answer, I prefer the first solution because it's the shorter one. The second is doing the same but it's more to write. &lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 09:36:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292865#M161120</guid>
      <dc:creator>bosch_softtec</dc:creator>
      <dc:date>2017-05-16T09:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: group different source in one querry</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292866#M161121</link>
      <description>&lt;P&gt;@bosch_softtec.. Please go ahead and Accept 1st answer by @dineshraj9. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 15:40:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292866#M161121</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-05-16T15:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: group different source in one querry</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292867#M161122</link>
      <description>&lt;P&gt;I downvoted this post because prefer the first solution because it's the shorter one&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 07:39:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292867#M161122</guid>
      <dc:creator>bosch_softtec</dc:creator>
      <dc:date>2017-05-17T07:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: group different source in one querry</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292868#M161123</link>
      <description>&lt;P&gt;@bosch_softtec... kindly read Splunk Community guideline and downvote only if the answer provided is incorrect or wrong. As you have already verified both the answers are correct. Query may be lengthy but might perform better. As it always exists with every question that there are multiple solutions, I was just giving you one more option.&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunkbase/splunkbase/Answers/Splunkcommunityguidelines"&gt;http://docs.splunk.com/Documentation/Splunkbase/splunkbase/Answers/Splunkcommunityguidelines&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You should ideally upvote all the options that work or help you and Accept the one that fits exactly as per your need. I am indeed glad that one of us was able to assist you. If rex has worked for you, next step for you should be to create a &lt;STRONG&gt;Field Extraction&lt;/STRONG&gt; so that the regular expression persists as a Knowledge Object and is easy to maintain. &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/ExtractfieldsinteractivelywithIFX"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/ExtractfieldsinteractivelywithIFX&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 08:34:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-different-source-in-one-querry/m-p/292868#M161123</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-05-17T08:34:50Z</dc:date>
    </item>
  </channel>
</rss>

