<?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: Add sample message to stats aggregation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173137#M49657</link>
    <description>&lt;P&gt;It does help and that's why I upvoted it, but it looks like it's creating different entries when the &lt;CODE&gt;sample&lt;/CODE&gt; is different. What I wanted is group by &lt;CODE&gt;hostname&lt;/CODE&gt; and &lt;CODE&gt;py_module:line#&lt;/CODE&gt; and then show one sample line.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jun 2015 21:06:54 GMT</pubDate>
    <dc:creator>BorrajaX</dc:creator>
    <dc:date>2015-06-23T21:06:54Z</dc:date>
    <item>
      <title>Add sample message to stats aggregation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173134#M49654</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;

&lt;P&gt;I would like to know if there's a way of adding a sample with the full contents of an event (the &lt;CODE&gt;_raw&lt;/CODE&gt; would suffice) when creating a table with &lt;CODE&gt;stats&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Let me elaborate: Let's say my servers log messages that, among others, it contains the keys &lt;EM&gt;hostname&lt;/EM&gt; (to identify the machine's name it came from) plus the &lt;EM&gt;Python module&lt;/EM&gt; and l*ine within the module* where the log message was generated. Something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;15:57:31 &amp;lt;155&amp;gt; server01 py_module=foo_module:30 This is a foo message
15:57:32 &amp;lt;187&amp;gt; server02 py_module=bar_module:65 Something happened here with wat
15:57:32 &amp;lt;187&amp;gt; server01 py_module=bar_module:65 Something happened here with blugh
15:57:33 &amp;lt;187&amp;gt; server01 py_module=bar_module:65 Something happened here with who knows?
15:57:34 &amp;lt;155&amp;gt; server02 py_module=foo_module:30 This is a bar message
15:57:35 &amp;lt;155&amp;gt; server02 py_module=foo_module:30 This is a baz message
15:57:33 &amp;lt;187&amp;gt; server01 py_module=bar_module:65 Something happened here with wooot???
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So... I have no problem grouping by &lt;CODE&gt;hostname&lt;/CODE&gt; and outputting a table with the most verbose loggers. Something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-24h 
    | rex field=host "(?&amp;lt;host_name&amp;gt;[a-zA-Z]+)\d*" 
    | stats count by host_name, py_module
    | sort -count 
    | head 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which produces a neat table like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;+----------------+---------------+-----------+
|    host_name   |   py_module   |   count   |
+----------------+---------------+-----------+
|      server    | foo_module:30 |     3     |
|      server    | bar_module:65 |     4     |
+----------------+---------------+-----------+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, what I'd like, is showing one extra column with one of the messages captured. I don't really care which one... Just one (could be the first matched, the last matched... whatever) so the table looks like:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Desired result:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;+----------------+---------------+-----------+-------------------------------------+
|    host_name   |   py_module   |   count   |                 sample              |
+----------------+---------------+-----------+-------------------------------------+
|      server    | foo_module:30 |     3     |   This is a foo message             |
|      server    | bar_module:65 |     4     |   Something happened here with wat  |
+----------------+---------------+-----------+-------------------------------------+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As mentioned before, at this point, I'd be happy if I could get one of the &lt;CODE&gt;_raw&lt;/CODE&gt;s, showing the full event (no need to show only the contents of the message itself, is what I mean)&lt;/P&gt;

&lt;P&gt;Is this even possible? I'd like to add some of the tries I've done (all of them with &lt;CODE&gt;subsearch&lt;/CODE&gt;es) but I always get a &lt;CODE&gt;No results found&lt;/CODE&gt; warning so I'd say it's kind of pointless...&lt;/P&gt;

&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:21:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173134#M49654</guid>
      <dc:creator>BorrajaX</dc:creator>
      <dc:date>2020-09-28T20:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Add sample message to stats aggregation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173135#M49655</link>
      <description>&lt;P&gt;Hi BorrajaX,&lt;/P&gt;

&lt;P&gt;try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-24h 
 | rex field=host "(?&amp;lt;host_name&amp;gt;[a-zA-Z]+)\d*" 
 | rex field=_raw ":\d{2}\s(?&amp;lt;sample&amp;gt;[\w\s]+)$"
 | stats count by host_name, py_module, sample
 | sort -count 
 | head 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will create a new field called &lt;CODE&gt;sample&lt;/CODE&gt; containing any alphanumeric and white space character after&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;a : and two digits and a white space until the end of the line
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2015 20:44:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173135#M49655</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-06-23T20:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add sample message to stats aggregation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173136#M49656</link>
      <description>&lt;P&gt;In the ideal case, you would extract the message component into its own field, but we can use &lt;CODE&gt;_raw&lt;/CODE&gt; for now. With &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.3/SearchReference/CommonStatsFunctions"&gt;stats functions&lt;/A&gt; capturing the first value is quite easy. We could just add an additional calculation to your stats statement (using the &lt;CODE&gt;first&lt;/CODE&gt; function) like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count first(_raw) as sample by host_name, py_module
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jun 2015 20:46:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173136#M49656</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-06-23T20:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Add sample message to stats aggregation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173137#M49657</link>
      <description>&lt;P&gt;It does help and that's why I upvoted it, but it looks like it's creating different entries when the &lt;CODE&gt;sample&lt;/CODE&gt; is different. What I wanted is group by &lt;CODE&gt;hostname&lt;/CODE&gt; and &lt;CODE&gt;py_module:line#&lt;/CODE&gt; and then show one sample line.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2015 21:06:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-sample-message-to-stats-aggregation/m-p/173137#M49657</guid>
      <dc:creator>BorrajaX</dc:creator>
      <dc:date>2015-06-23T21:06:54Z</dc:date>
    </item>
  </channel>
</rss>

