<?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 Get all events in a 1-minute time window around an error events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742654#M240894</link>
    <description>&lt;P&gt;I have a stream of logs from a system.&lt;BR /&gt;&lt;BR /&gt;To filter for errors, I can perform a search like so:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=project1 sourcetype=pc1 log_data="*error*"&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I can use it to get errors however I also want the events surrounding this error as well. I want to be able to get all events that occurred 1 minute before and 1 minute after (all events, not just errors).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What would be the best possible way to achieve this?&lt;/P&gt;</description>
    <pubDate>Wed, 26 Mar 2025 05:20:32 GMT</pubDate>
    <dc:creator>db2</dc:creator>
    <dc:date>2025-03-26T05:20:32Z</dc:date>
    <item>
      <title>Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742654#M240894</link>
      <description>&lt;P&gt;I have a stream of logs from a system.&lt;BR /&gt;&lt;BR /&gt;To filter for errors, I can perform a search like so:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=project1 sourcetype=pc1 log_data="*error*"&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I can use it to get errors however I also want the events surrounding this error as well. I want to be able to get all events that occurred 1 minute before and 1 minute after (all events, not just errors).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What would be the best possible way to achieve this?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 05:20:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742654#M240894</guid>
      <dc:creator>db2</dc:creator>
      <dc:date>2025-03-26T05:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742656#M240895</link>
      <description>&lt;P&gt;It is rare that I, or anyone here, recommends &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Map" target="_blank" rel="noopener"&gt;map&lt;/A&gt; command but this seems to be an appropriate use case if errors are rare and far in between.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=project1 sourcetype=pc1 log_data="*error*"
| eval early = _time - 60, late = _time + 60
| map search="search index=project1 sourcetype=pc1 earliest=$early$ latest=$late$"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 05:38:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742656#M240895</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2025-03-26T05:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742657#M240896</link>
      <description>&lt;P&gt;There are two ways about it. One is the map command as shown by &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; . Another one is using subsearch.&lt;/P&gt;&lt;P&gt;The subsearch has its limitations and can be silently finalized early producing incomplete results. But the map command is one of the risky commands and a normal user can be forbidden from running it.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 05:54:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742657#M240896</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-03-26T05:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742748#M240938</link>
      <description>&lt;P&gt;Technically there is a 3rd option (and often with Splunk there may be a 4th), but this example shows you how to first detect errors and then mark the events that fit within the window required of that error.&lt;/P&gt;&lt;P&gt;It creates 40 random events with an occasional error then it basically copies the error time up and down the non-error events and then filters those that match the time window of the closest error.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=40
| streamstats c
| eval _time=now() - c*20
| eval log_data=if(c % (random() % 30) = 0, "bla error message bla", "normal event message")
| fields - c
``` The above creates a simple 40 event data set with an occasional error ```

``` Ensure time descending order and mark the events that have an error ```
| sort - _time
| streamstats window=1 values(eval(if(match(log_data,"error"), _time, null()))) as error_time

``` Save the error time and copy the error time down to all following records until the next error ```
| eval start_time=error_time
| filldown error_time
``` Now filter events within 60 seconds prior to the error ```
| eval INCLUDE=if(_time&amp;gt;=(error_time-60) AND _time&amp;lt;=error_time, "YES", "NO")

``` Now do the same in reverse, i.e. time ascending order ```
| sort _time
| filldown start_time
``` and filter events that are within 60 seconds AFTER the error ```
| eval INCLUDE=if(_time&amp;lt;=(start_time+60) AND _time&amp;gt;=start_time, "YES", INCLUDE)
| fields - start_time error_time&lt;/LI-CODE&gt;&lt;P&gt;Bear in mind that this could be an expensive search as it does 2 sorts and 2 streamstats, but&amp;nbsp;in your case you could do&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=project1 sourcetype=pc1&lt;/LI-CODE&gt;&lt;P&gt;followed by the SPL after the data setup above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 22:15:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742748#M240938</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-03-26T22:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742763#M240942</link>
      <description>&lt;P&gt;Yes. There is this mark and select approach but it requires Splunk to not only scan all events from the initial search timerange, it also requires it to hold them as immediate results for the purpose of reversing.&amp;nbsp; So it's not really a practical solution. But yes, it can be done this way.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 05:34:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/742763#M240942</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-03-27T05:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743055#M241004</link>
      <description>&lt;P&gt;Thank you for the help bowesmana. This solution works but it seems to cap my results to 10k Events, is this an inherent splunk thing or am I missing a piece of the puzzle?&lt;BR /&gt;&lt;BR /&gt;I did do a search for only the INCLUDE=YES events&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;``` Ensure time descending order and mark the events that have an error ```
| sort - _time
| streamstats window=1 values(eval(if(match(log_data,"error"), _time, null()))) as error_time

``` Save the error time and copy the error time down to all following records until the next error ```
| eval start_time=error_time
| filldown error_time
``` Now filter events within 60 seconds prior to the error ```
| eval INCLUDE=if(_time&amp;gt;=(error_time-60) AND _time&amp;lt;=error_time, "YES", "NO")

``` Now do the same in reverse, i.e. time ascending order ```
| sort _time
| filldown start_time
``` and filter events that are within 60 seconds AFTER the error ```
| eval INCLUDE=if(_time&amp;lt;=(start_time+60) AND _time&amp;gt;=start_time, "YES", INCLUDE)
| fields - start_time error_time

| search INCLUDE=YES&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Mar 2025 22:47:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743055#M241004</guid>
      <dc:creator>db2</dc:creator>
      <dc:date>2025-03-30T22:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743061#M241006</link>
      <description>&lt;P&gt;max_stream_window = &amp;lt;integer&amp;gt;&lt;BR /&gt;* For the streamstats command, the maximum allow window size.&lt;BR /&gt;* Default: 10000&lt;/P&gt;&lt;P&gt;This is probably the cause.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Mar 2025 23:22:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743061#M241006</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-03-30T23:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743071#M241008</link>
      <description>&lt;P&gt;Thank you PickleRick, this was probably the reason, unfortunately I couldn't edit the max_stream_window.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 05:02:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743071#M241008</guid>
      <dc:creator>db2</dc:creator>
      <dc:date>2025-03-31T05:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743072#M241009</link>
      <description>&lt;P&gt;Actually, it's the sort command that is capping the results to 10k - always bites me, if you want to sort ALL results you must do &lt;STRONG&gt;sort 0 - ...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Glad to hear it worked.&lt;/P&gt;&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;said, recommending map is not often found here, as it will run the map command sequentially, but if you have few errors, then the map will not have to make many iterations, but by default it will only run over 10 results unless you override the params.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 04:56:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743072#M241009</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-03-31T04:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Get all events in a 1-minute time window around an error events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743321#M241072</link>
      <description>&lt;P&gt;How about this, if you don't need to get those immediately with your 1st search.&lt;/P&gt;&lt;P&gt;Just make you search. Then click correct event and open it from &amp;gt; mark in beginning of event then click _time fields and it opens to you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="isoutamo_0-1743629586163.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/38429i10A60847BE711A06/image-size/medium?v=v2&amp;amp;px=400" role="button" title="isoutamo_0-1743629586163.png" alt="isoutamo_0-1743629586163.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then just select correct time slot and do search again without any "matching words" like 'log_data="*error*"'&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2025 21:34:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-all-events-in-a-1-minute-time-window-around-an-error-events/m-p/743321#M241072</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2025-04-02T21:34:37Z</dc:date>
    </item>
  </channel>
</rss>

