<?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: How to produce stats with based on a field clientId in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513186#M144048</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/222349"&gt;@shashank_24&lt;/a&gt;&amp;nbsp;for the community to assist you better you may have to provide some more details like mock/anonymized sample data from both sourcetype. Also what is the output of current query or till what point is your query working?&lt;/P&gt;&lt;P&gt;Based on the details provided your query should work, however following would have been better way to write the SPL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=test (sourcetype=splunk_log event=AUTHN_ATTEMPT clientId=* status=inprogress) OR (source="server.log" AND "In processPasswordCredential" AND ("found but failed" OR "found and success"))
| rex field=_raw "sessionid\=\"id\:(?&amp;lt;id&amp;gt;[^\"]+)"
| eval status_new=case(searchmatch("found and success"),"Success", searchmatch("found but failed"),"Fail")
| stats count(eval(status_new=="Success")) as SuccessCount count(eval(status_new=="Fail")) as FailedAttemptCount by id&lt;/LI-CODE&gt;&lt;P&gt;If above query or your SPL is not working at present please provide more details. Is the &lt;STRONG&gt;sessionid&lt;/STRONG&gt; field present in both the sourcetypes? If not how can the id be extracted from &lt;STRONG&gt;server.log&lt;/STRONG&gt; source? Is it automatically extracted? (as you have provided no details in your question and SPL does not include that extraction).&lt;/P&gt;</description>
    <pubDate>Sun, 09 Aug 2020 05:19:23 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-08-09T05:19:23Z</dc:date>
    <item>
      <title>How to produce stats with based on a field clientId</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513028#M144047</link>
      <description>&lt;P&gt;Hi, I am stuck at a query problem. So what i need to do is join some events and get the result and for that I am using stats. I can't use join because of the sub-search limitation. Below is my query.&lt;/P&gt;&lt;P&gt;The common field in the events is &lt;STRONG&gt;id &lt;/STRONG&gt;which i am extracting but what I want to do is produce a table based on clientId (like below) but the current query does not give what i require.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;clientId&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;SuccessCount&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;FailedAttemptCount&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;client1&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;client2&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;client3&lt;/TD&gt;&lt;TD&gt;5500&lt;/TD&gt;&lt;TD&gt;450&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is my one event contains clientId (sourcetype=splunk_audit_log event=AUTHN_ATTEMPT clientId=* status=inprogress) and another event contain whether that client was successful during login attempt (source="server.log" "In processCredentials" )&lt;/P&gt;&lt;P&gt;The query which i created is -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=test (sourcetype=splunk_log event=AUTHN_ATTEMPT clientId=* status=inprogress) OR (source="server.log" "In processPasswordCredential" NOT "not found!")
| rex field=_raw "user\=\[\d+\] (?&amp;lt;raw_status&amp;gt;.*)" 
| rex field=_raw "sessionid\=\"id\:(?&amp;lt;id&amp;gt;[^\"]+)"
| eval status_new=case(raw_status="found and success","Success", raw_status="found but failed","Fail")
| stats list(status_new) as aa_status by id 
| eval NumberOfSuccess=mvfilter(match(aa_status, "Success"))
| eval NumberOfFail=mvfilter(match(aa_status, "Fail"))
| eval SuccessCount = mvcount(NumberOfSuccess)
| eval FailedAttemptCount = mvcount(NumberOfFail)
| fields - NumberOfSuccess NumberOfFail count aa_status&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let me know if someone can help please. Appreciate your support.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Aug 2020 15:25:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513028#M144047</guid>
      <dc:creator>shashank_24</dc:creator>
      <dc:date>2020-08-07T15:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to produce stats with based on a field clientId</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513186#M144048</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/222349"&gt;@shashank_24&lt;/a&gt;&amp;nbsp;for the community to assist you better you may have to provide some more details like mock/anonymized sample data from both sourcetype. Also what is the output of current query or till what point is your query working?&lt;/P&gt;&lt;P&gt;Based on the details provided your query should work, however following would have been better way to write the SPL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=test (sourcetype=splunk_log event=AUTHN_ATTEMPT clientId=* status=inprogress) OR (source="server.log" AND "In processPasswordCredential" AND ("found but failed" OR "found and success"))
| rex field=_raw "sessionid\=\"id\:(?&amp;lt;id&amp;gt;[^\"]+)"
| eval status_new=case(searchmatch("found and success"),"Success", searchmatch("found but failed"),"Fail")
| stats count(eval(status_new=="Success")) as SuccessCount count(eval(status_new=="Fail")) as FailedAttemptCount by id&lt;/LI-CODE&gt;&lt;P&gt;If above query or your SPL is not working at present please provide more details. Is the &lt;STRONG&gt;sessionid&lt;/STRONG&gt; field present in both the sourcetypes? If not how can the id be extracted from &lt;STRONG&gt;server.log&lt;/STRONG&gt; source? Is it automatically extracted? (as you have provided no details in your question and SPL does not include that extraction).&lt;/P&gt;</description>
      <pubDate>Sun, 09 Aug 2020 05:19:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513186#M144048</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-08-09T05:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to produce stats with based on a field clientId</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513265#M144049</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt;, Thank you for the quick response. My query works perfectly fine when i split by using sessionid but what i want is to split by using clientId (consumer). There are multiple clientId's so what i want to know the count of failed attempt and count of success attempt from a particular clientId like a table mentioned in the question.&lt;/P&gt;&lt;P&gt;Also the sessionIs is present in both the events and getting extracted successfully and i am able to get the data by sessionId but my requirement is different.&lt;/P&gt;&lt;P&gt;These are the chain of events - User attempts and then we get the response whether it's successful or not. You can see the clientId field in first event but it's not there in 2nd and I want to split by that.&lt;BR /&gt;&lt;STRONG&gt;The only common field is sessionId&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2020-08-09 23:59:56,455 sessionid:jhdjbmclsodhe3865dfd event=AUTHN_ATTEMPT ip=198.10.973.146 app= clientId=myApp1 status=inprogress adapterid=temp attributes="" description="" nmessagetype="Request" 

2020-08-09 15:10:57,674 sessionid:jhdjbmclsodhe3865dfd INFO "In processCredentials" VERIFIED user=temp@gmail.com userid=[1111111] found and success&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 08:16:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513265#M144049</guid>
      <dc:creator>shashank_24</dc:creator>
      <dc:date>2020-08-10T08:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to produce stats with based on a field clientId</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513274#M144050</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="
2020-08-09 23:59:56,455 sessionid:jhdjbmclsodhe3865dfd event=AUTHN_ATTEMPT ip=198.10.97.146 app= clientId=myApp1 status=inprogress adapterid=temp attributes=\"\" description=\"\" nmessagetype=\"Request\" 
2020-08-09 23:58:56,455 sessionid:jhdjbmclsodhe3865df3 event=AUTHN_ATTEMPT ip=198.10.97.147 app= clientId=myApp2 status=inprogress adapterid=temp attributes=\"\" description=\"\" nmessagetype=\"Request\" 
2020-08-09 15:10:57,674 sessionid:jhdjbmclsodhe3865dfd INFO \"In processCredentials\" VERIFIED user=temp@gmail.com userid=[1111111] found and success
2020-08-09 15:10:57,674 sessionid:jhdjbmclsodhe3865df3 INFO \"In processCredentials\" VERIFIED user=temp1@gmail.com userid=[1111112] found but failed" 
| multikv noheader=t 
| fields _raw 
| eval _time=strptime(substr(_raw,1,23),"%F %T,%3Q") 
| rename COMMENT as "this is your sample. from here, the logic" 
| extract pairdelim=" " kvdelim=":=" 
| eval status_new=case(searchmatch("found and success"),"Success", searchmatch("found but failed"),"Fail") 
| stats values(clientId) as clientId count(eval(status_new="Success")) as Success count(eval(status_new="Fail")) as Fail by sessionid 
| fields - sessionid&lt;/LI-CODE&gt;&lt;P&gt;When the log displays, it's easy to make the query.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 08:58:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513274#M144050</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-08-10T08:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to produce stats with based on a field clientId</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513291#M144051</link>
      <description>&lt;P&gt;Based on sample data provided add the following to your existing query&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;yourCurrentSearch&amp;gt;
| rex field=_raw "sessionid\:(?&amp;lt;sessionid&amp;gt;[^\s]+)"
| stats values(clientId) as clientId count(eval(searchmatch("found and success"))) as SuccessCount count(eval(searchmatch("found but failed"))) as FailedAttemptCount by sessionid
| stats sum(SuccessCount) as SuccessCount sum(FailedAttemptCount) as FailedAttemptCount by clientId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following is a run anywhere search which uses data provided by you. (commands till | KV generate the sample data). I have changed sessionid regular expression extraction as per your sample data. You may not need that change if data session id has double quotes for your actual data.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="2020-08-09 23:59:56,455 sessionid:abc123 event=AUTHN_ATTEMPT ip=10.10.10.10 app=blah clientId=myApp1 status=inprogress adapterid=temp attributes=\"\" description=\"\" nmessagetype=\"Request\""
| append [| makeresults
| eval _raw="2020-08-09 15:10:57,674 sessionid:abc123 INFO \"In processCredentials\" VERIFIED user=temp@gmail.com userid= 
    [ 1111111] found and success"]
| KV
| rex field=_raw "sessionid\:(?&amp;lt;sessionid&amp;gt;[^\s]+)"
| stats values(clientId) as clientId count(eval(searchmatch("found and success"))) as SuccessCount count(eval(searchmatch("found but failed"))) as FailedAttemptCount by sessionid
| stats sum(SuccessCount) as SuccessCount sum(FailedAttemptCount) as FailedAttemptCount by clientId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 09:40:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513291#M144051</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-08-10T09:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to produce stats with based on a field clientId</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513542#M144084</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/184221"&gt;@to4kawa&lt;/a&gt;&amp;nbsp;Thank you both for your help and response. I have tried using&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt;&amp;nbsp;query and it satisfies my requirement. I am able to split the data by using clientID and it gives me the sum of success and failed login attempts by clientId.&lt;/P&gt;&lt;P&gt;Thanks again both of you. You guys are stars &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 10:59:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-produce-stats-with-based-on-a-field-clientId/m-p/513542#M144084</guid>
      <dc:creator>shashank_24</dc:creator>
      <dc:date>2020-08-11T10:59:51Z</dc:date>
    </item>
  </channel>
</rss>

