<?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: Statistics based on regex and quotes in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346924#M5453</link>
    <description>&lt;P&gt;FailureCount is different.  I've updated my answer.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2017 15:14:23 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2017-08-03T15:14:23Z</dc:date>
    <item>
      <title>Statistics based on regex and quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346921#M5450</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I am new to Splunk and I managed to construct the below query to generate statistics(getting count of customers grouped by REQ). However I wanted to add four more columns with count values.&lt;BR /&gt;
One for Success, one for failure, one for type of request(GET/POST etc), one for language&lt;/P&gt;

&lt;P&gt;Success count should be counted based on HTTPRES="200 OK".&lt;BR /&gt;
For failure count the above will anything other than 200&lt;BR /&gt;
Request should be whether it is GET/POST etc. Obtained from Rest="GET h t t p ://.........". The characters after Rest="&lt;BR /&gt;
Langage is the trickiest part. We need to extract 'gr/gr' from this url  url starting with http/somealphabets/alphabets/gr/gr/....continues. &lt;/P&gt;

&lt;P&gt;sample log, the url link starts with http,  as I cant post any links directly now.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Aug 03 07:53:34 servername_APP_LOG [IN_PROD][12345678][APP_LOG][note] abc(NewService): Id(125678)[RESP][1.2.3.4] Globid(45678912): REQ=ABC.ElectronicsService,Customer=JIKL,NUM=34872,HTTPRES="200 OK",Fromcache=true,Result="",Op_name=ABCElectronicsService.getallpages.v1.0,Receive=Accepted,Policy=onepermin,Value=345,time=1,spent=2,Size=2,RspSize=123,Format=json,Actual=,remaining=2.3.4.5,Rest="GET url starting with http/salo/vbghj/gr/gr/val/prot/34567",Rwe="",Notice="",GH="version 1.1"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My cuurent query(query is fine)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"[APP_LOG]" "[IN_PROD]"
 | stats count as RequestCount count(Customer=*) by Customer, REQ

  | table Customer, REQ, RequestCount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;yields&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  Customer          REQ                                  RequestCount
  JIKL              ABC.ElectronicsService               5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Wanted like below table. Sorry for bad formatting&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  Customer  REQ                 RequestCount       SuccessCount   Failure  Request          Language
  JIKL            ABC.ElectronicsService               5                    3           2         GET                gr/gr
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 09:35:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346921#M5450</guid>
      <dc:creator>jaango123</dc:creator>
      <dc:date>2017-08-03T09:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Statistics based on regex and quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346922#M5451</link>
      <description>&lt;P&gt;Getting the success count can be done using &lt;CODE&gt;eval&lt;/CODE&gt; within &lt;CODE&gt;stats&lt;/CODE&gt;.  &lt;CODE&gt;... | stats count(eval(HTTPRES="200 OK")) as SuccessCount&lt;/CODE&gt;. Get the failure count with a similar command.  &lt;CODE&gt;... | stats count(eval(HTTPRES="200 OK")) as FailureCount&lt;/CODE&gt;.&lt;BR /&gt;
Pulling language out of the URL is not so bad, assuming the URL format is consistent with your example.  &lt;CODE&gt;rex&lt;/CODE&gt; handles that.  &lt;CODE&gt;... rex "https?:\/\/.*?\/.*?\/(?&amp;lt;language&amp;gt;\w\w\/\w\w)\/"&lt;/CODE&gt;.  The same can be said for Request.&lt;/P&gt;

&lt;P&gt;Putting it all together looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"[APP_LOG]" "[IN_PROD]"
| rex "https?:\/\/.*?\/.*?\/(?&amp;lt;language&amp;gt;\w\w\/\w\w)\/"
| rex "rest=\"(?&amp;lt;Request&amp;gt;\w+)"
| stats count as RequestCount count(Customer=*) count(eval(HTTPRES="200 OK")) as SuccessCount count(eval(HTTPRES!="200 OK")) as FailureCount values(language) as Language values(Request) as Request by Customer, REQ
| table Customer, REQ, RequestCount, SuccessCount, FailureCount, Request, Language
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 13:01:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346922#M5451</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-08-03T13:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Statistics based on regex and quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346923#M5452</link>
      <description>&lt;P&gt;Thanks.. I will try this. However the FailureCount is same as Successcount?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 14:51:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346923#M5452</guid>
      <dc:creator>jaango123</dc:creator>
      <dc:date>2017-08-03T14:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Statistics based on regex and quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346924#M5453</link>
      <description>&lt;P&gt;FailureCount is different.  I've updated my answer.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 15:14:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346924#M5453</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-08-03T15:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Statistics based on regex and quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346925#M5454</link>
      <description>&lt;P&gt;Thanks.. It shows how to use Regex and to group fields. Can you please let me know how to modify this so that i can group by Language as well. I get an error "The output field cannot have the same name Language as the group by field"&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 07:16:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Statistics-based-on-regex-and-quotes/m-p/346925#M5454</guid>
      <dc:creator>jaango123</dc:creator>
      <dc:date>2017-08-04T07:16:24Z</dc:date>
    </item>
  </channel>
</rss>

