<?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: Advanced Nested query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Advanced-Nested-query/m-p/76503#M19357</link>
    <description>&lt;P&gt;You don't have to run nested queries, what you've got there is a classic example of using the stats command.&lt;/P&gt;

&lt;P&gt;First thing, if the fields are not already available to be manipulated, you need to extract them.&lt;/P&gt;

&lt;P&gt;Here's an example to capture the loginid and the message&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "[^:]+:[^:]+:[^:]+:(?&amp;lt;loginid&amp;gt;[^\s]+)\s+(?&amp;lt;message&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then we can perform some stats&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count(eval(match(message,"Success"))) as Logins count(eval(match(message,"Failed"))) as Failures count(eval(match(message,"Error"))) as as Errors by loginid
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So taking "Logins" as an example, this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;count(eval(match(message,"Success"))) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is saying, try to match 'Success' in the message&lt;BR /&gt;&lt;BR /&gt;
The eval surrounding it either returns 1 for success, or NULL for a failure&lt;BR /&gt;&lt;BR /&gt;
Then we count up the number of Successes per loginid&lt;/P&gt;

&lt;P&gt;Repeat for Failures and Errors&lt;/P&gt;</description>
    <pubDate>Thu, 03 Jan 2013 10:42:47 GMT</pubDate>
    <dc:creator>jonuwz</dc:creator>
    <dc:date>2013-01-03T10:42:47Z</dc:date>
    <item>
      <title>Advanced Nested query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Advanced-Nested-query/m-p/76501#M19355</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;My logs have data in following format:&lt;/P&gt;

&lt;P&gt;" session:host:loginid some-event-data"&lt;BR /&gt;
Ex: 123:abcd:test1 Login Attempt&lt;BR /&gt;
Ex: 123:abcd:test2 Login Success&lt;BR /&gt;
Ex: 123:abcd:test1 Login Failed&lt;BR /&gt;
Ex: 123:abcd:test2 Reset the passoword&lt;BR /&gt;
Ex: 123:abcd:test3 Encountered Error in Profile&lt;/P&gt;

&lt;P&gt;I need to generate a report as below: &lt;/P&gt;

&lt;P&gt;LoginID Logins Failures Errors&lt;BR /&gt;
Test1 10 2 30&lt;BR /&gt;
Test2 2 1 1 &lt;BR /&gt;
Test3 4 5 6&lt;/P&gt;

&lt;P&gt;I tried "Query1 | stats count as Logins | appendcols [search Query2 | stats count as Failures] | appendcols [search Query3 | stats count as Errors]" But it gives results for all users not per user stats as Below. &lt;/P&gt;

&lt;P&gt;Logins Failures Errors&lt;BR /&gt;
100 200 150&lt;/P&gt;

&lt;P&gt;How to pull the records per users? How do I run 3 nested queries for each user?&lt;/P&gt;

&lt;P&gt;Thanks in Advance.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2013 09:57:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Advanced-Nested-query/m-p/76501#M19355</guid>
      <dc:creator>webshan</dc:creator>
      <dc:date>2013-01-03T09:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Nested query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Advanced-Nested-query/m-p/76502#M19356</link>
      <description>&lt;P&gt;You don't need three queries, you can do this with a single stats command, assuming you have extracted loginid as a field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=my_login_sourcetype | stats count(eval(searchmatch("Success"))) as Logins count(eval(searchmatch("Failed"))) as Failures count(eval(searchmatch("Error"))) as Errors by loginid
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Jan 2013 10:25:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Advanced-Nested-query/m-p/76502#M19356</guid>
      <dc:creator>dart</dc:creator>
      <dc:date>2013-01-03T10:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Nested query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Advanced-Nested-query/m-p/76503#M19357</link>
      <description>&lt;P&gt;You don't have to run nested queries, what you've got there is a classic example of using the stats command.&lt;/P&gt;

&lt;P&gt;First thing, if the fields are not already available to be manipulated, you need to extract them.&lt;/P&gt;

&lt;P&gt;Here's an example to capture the loginid and the message&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "[^:]+:[^:]+:[^:]+:(?&amp;lt;loginid&amp;gt;[^\s]+)\s+(?&amp;lt;message&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then we can perform some stats&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count(eval(match(message,"Success"))) as Logins count(eval(match(message,"Failed"))) as Failures count(eval(match(message,"Error"))) as as Errors by loginid
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So taking "Logins" as an example, this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;count(eval(match(message,"Success"))) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is saying, try to match 'Success' in the message&lt;BR /&gt;&lt;BR /&gt;
The eval surrounding it either returns 1 for success, or NULL for a failure&lt;BR /&gt;&lt;BR /&gt;
Then we count up the number of Successes per loginid&lt;/P&gt;

&lt;P&gt;Repeat for Failures and Errors&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2013 10:42:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Advanced-Nested-query/m-p/76503#M19357</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-01-03T10:42:47Z</dc:date>
    </item>
  </channel>
</rss>

