<?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: Iterate through the results of a query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138139#M37901</link>
    <description>&lt;P&gt;you wrote "how many error messages have value 1" not value X. And your searches weren't even using the right field names. Thats where i thought you were going wrong.&lt;/P&gt;

&lt;P&gt;You could simply use a subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=* [search index=* errorid=1 | table errorid] | stats count, dc(errorid), values(errorid) by hostname
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 Feb 2015 12:08:43 GMT</pubDate>
    <dc:creator>cchitten</dc:creator>
    <dc:date>2015-02-16T12:08:43Z</dc:date>
    <item>
      <title>Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138136#M37898</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have a query that gives me a result in a name value format in a table.&lt;BR /&gt;
Basically I work with log lines and I'm counting how many times one field has a discreet value.&lt;/P&gt;

&lt;P&gt;Log lines can be e.g.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;errorid=1 hostname=a value=1
errorid=1 hostname=b value=3
errorid=1 hostname=a value=2
errorid=1 hostname=c value=1
errorid=2 hostname=c value=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm able to create a query like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;errorid=*| stats count(eval(errorid='1') by hostname as Host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;errorid=* | stats count(eval(errorid='1') by value as Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But what I'd need that get the result from the first query and run the second against that subset.&lt;BR /&gt;
So I'd like to find out that how many error messages have value X on a given host and get this for all hosts that appear in these kind of messages.&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Feb 2015 10:48:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138136#M37898</guid>
      <dc:creator>DJPillowhead</dc:creator>
      <dc:date>2015-02-16T10:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138137#M37899</link>
      <description>&lt;P&gt;does this work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;errorid=1 | stats count by hostname
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Feb 2015 11:09:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138137#M37899</guid>
      <dc:creator>cchitten</dc:creator>
      <dc:date>2015-02-16T11:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138138#M37900</link>
      <description>&lt;P&gt;Thanks, but that's written there in my question. I'd like to have a result that shows how many errors came with hostname "somehing" AND on a third column, how much of these had value x.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Feb 2015 11:37:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138138#M37900</guid>
      <dc:creator>DJPillowhead</dc:creator>
      <dc:date>2015-02-16T11:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138139#M37901</link>
      <description>&lt;P&gt;you wrote "how many error messages have value 1" not value X. And your searches weren't even using the right field names. Thats where i thought you were going wrong.&lt;/P&gt;

&lt;P&gt;You could simply use a subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=* [search index=* errorid=1 | table errorid] | stats count, dc(errorid), values(errorid) by hostname
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Feb 2015 12:08:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138139#M37901</guid>
      <dc:creator>cchitten</dc:creator>
      <dc:date>2015-02-16T12:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138140#M37902</link>
      <description>&lt;P&gt;With your interaction with cchitten I'm not really sure what you are asking. Have you tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;errorid=* | stats count by hostname errorid value | sort hostname errorid
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will give you the individual counts of unique events. You could then do additional stats or eventstats commands if you wanted to find other pieces of summary data. I guess if that doesn't help I'd suggest posting an example of hoped for outcome.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Feb 2015 12:28:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138140#M37902</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2015-02-16T12:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138141#M37903</link>
      <description>&lt;P&gt;Thanks for your answer, I've made my initial question more straightforward.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Feb 2015 13:05:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138141#M37903</guid>
      <dc:creator>DJPillowhead</dc:creator>
      <dc:date>2015-02-16T13:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138142#M37904</link>
      <description>&lt;P&gt;Output should be a table something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;errorid | hostname | count
1 | a | 5
1 | b | 2
1 | c | 4
2 | a | 5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Feb 2015 13:08:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138142#M37904</guid>
      <dc:creator>DJPillowhead</dc:creator>
      <dc:date>2015-02-16T13:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through the results of a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138143#M37905</link>
      <description>&lt;P&gt;easy then - just a stats count by errorid hostname. Again though assuming you aren't wanting to do something with the field "value". Of course you could get all fancy and do something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count by error hostname value | sort hostname | stats sum(count) as total_events list(hostname) as hostname list(value) as value by error
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since you seem to be interested in the error messages. If you wanted to focus more on the errors from a particular host you could reverse that to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count by error hostname value | sort hostname | stats sum(count) as total_events list(error) as error list(value) as value by hostname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course I'm partial to that sort of formatting but it doesn't translate well to PDF or csv output.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Feb 2015 13:27:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Iterate-through-the-results-of-a-query/m-p/138143#M37905</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2015-02-16T13:27:39Z</dc:date>
    </item>
  </channel>
</rss>

