<?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 write a Splunk search to group a few lines before and after a matching event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207152#M60389</link>
    <description>&lt;P&gt;Sorry to bring bad news, but this does not work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'autoregress' command: You cannot specify new field name when you specify a range for 'p'.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also remember this will only work if you don't use a filter in the base search otherwise &lt;CODE&gt;autoregress&lt;/CODE&gt; has only &lt;CODE&gt;_raw&lt;/CODE&gt; events containing the filter and nothing else.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2015 02:14:11 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2015-10-29T02:14:11Z</dc:date>
    <item>
      <title>How to write a Splunk search to group a few lines before and after a matching event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207150#M60387</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I need your help in making a search where I can group lines before and after a matching event in Splunk, same as this UNIX command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;grep -C 2 &amp;lt;string&amp;gt; &amp;lt;filename&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks... !!!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2015 07:05:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207150#M60387</guid>
      <dc:creator>ProudDevil</dc:creator>
      <dc:date>2015-10-28T07:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Splunk search to group a few lines before and after a matching event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207151#M60388</link>
      <description>&lt;P&gt;Like this (with &lt;CODE&gt;autoregress&lt;/CODE&gt; command):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... &amp;lt;string&amp;gt; | autoregress _raw AS PrevEventsp=1-3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.0/SearchReference/Autoregress"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.0/SearchReference/Autoregress&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;This can also can be done with &lt;CODE&gt;streamstats&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 02:06:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207151#M60388</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-29T02:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Splunk search to group a few lines before and after a matching event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207152#M60389</link>
      <description>&lt;P&gt;Sorry to bring bad news, but this does not work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'autoregress' command: You cannot specify new field name when you specify a range for 'p'.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also remember this will only work if you don't use a filter in the base search otherwise &lt;CODE&gt;autoregress&lt;/CODE&gt; has only &lt;CODE&gt;_raw&lt;/CODE&gt; events containing the filter and nothing else.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 02:14:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207152#M60389</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-10-29T02:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Splunk search to group a few lines before and after a matching event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207153#M60390</link>
      <description>&lt;P&gt;Hi ProudDevil,&lt;/P&gt;

&lt;P&gt;you can use &lt;CODE&gt;map&lt;/CODE&gt; to get those events; take this run everywhere search which will search &lt;CODE&gt;index=_internal&lt;/CODE&gt; for &lt;CODE&gt;kbps&lt;/CODE&gt; values over 35 in &lt;CODE&gt;metrics.log&lt;/CODE&gt; and will return the surrounding events from &lt;CODE&gt;sourcetype=splunkd&lt;/CODE&gt;, starting 2.5 minutes before the event and ending 2.5 minutes after the event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal source="*metrics.log" kbps&amp;gt;35 
| eval start_time=_time-150 
| eval end_time=start_time+150 
| map search="search index=_internal sourcetype=splunkd earliest=$start_time$ latest=$end_time$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can change the &lt;CODE&gt;map&lt;/CODE&gt; search to return events for the kbps and the surrounding events as well:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal source="*metrics.log" kbps&amp;gt;35 
| eval start_time=_time-150 
| eval end_time=start_time+150 
| map search="search index=_internal source="*metrics.log" earliest=$start_time$ latest=$end_time$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps to get you started ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 02:45:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207153#M60390</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-10-29T02:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Splunk search to group a few lines before and after a matching event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207154#M60391</link>
      <description>&lt;P&gt;@MuS is correct (that is what I get for not testing); the command should actually be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... &amp;lt;string&amp;gt; | eval raw=_raw | autoregress raw p=1-3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;He is also correct that this will only bring in the previous &lt;EM&gt;matching&lt;/EM&gt; events, not the events before the match.  So you would actually have to do it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... &amp;lt;base search that includes all events&amp;gt; | eval raw=_raw | autoregress raw p=1-3 | search &amp;lt;string&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This could be quicker than using &lt;CODE&gt;map&lt;/CODE&gt;, but it really depends on how many matches you have and how many events are in your base search.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 15:37:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Splunk-search-to-group-a-few-lines-before-and/m-p/207154#M60391</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-29T15:37:03Z</dc:date>
    </item>
  </channel>
</rss>

