<?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 select only one event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630730#M219115</link>
    <description>&lt;P&gt;How should Splunk know which events to display?&amp;nbsp; When does it choose the highest duration and when does it choose the first and third?&amp;nbsp; Computers need rules to follow.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2023 01:16:36 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2023-02-14T01:16:36Z</dc:date>
    <item>
      <title>How to select only one event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630621#M219088</link>
      <description>&lt;P&gt;My query is this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;index=log AND 1378&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two event&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;20230112, 1378, error A/B/C, duration 100&lt;/P&gt;
&lt;P&gt;20230112, 1378, error A/B, duration 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want select only one event that duration greater than another event.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 17:11:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630621#M219088</guid>
      <dc:creator>disasters</dc:creator>
      <dc:date>2023-02-13T17:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to select only one event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630622#M219089</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/230721"&gt;@disasters&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I suppose that you already extracted fields, so, please confirm:&lt;/P&gt;&lt;P&gt;you want to extract all the events for each event_id (1378) where there are more than one event and you want the one with the max duration, is it correct?&lt;/P&gt;&lt;P&gt;if this is your need, please try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=log 1378
| stats 
   earliest(timestamp) AS timestamp 
   values(error) AS error
   max(duration) AS duration
   count 
   BY event_id
| where count&amp;gt;1&lt;/LI-CODE&gt;&lt;P&gt;in addition, you don't need to use the AND operator because if you don't use a boolean operator is like AND.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 10:45:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630622#M219089</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-02-13T10:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to select only one event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630623#M219090</link>
      <description>&lt;P&gt;Assuming the duration field is already extracted, use &lt;FONT face="courier new,courier"&gt;eventstats&lt;/FONT&gt; to find the greatest duration then the &lt;FONT face="courier new,courier"&gt;where&lt;/FONT&gt; command can select the event with that value.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=log AND 1378
| eventstats max(duration) as maxDuration
| where duration = maxDuration&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 10:46:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630623#M219090</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-02-13T10:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to select only one event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630726#M219113</link>
      <description>&lt;P class="lia-align-left"&gt;It works. Thank you!!&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;more question...&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are four event&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. 20230112, 1378, error A/B/C, duration 100&lt;/P&gt;&lt;P&gt;2. 20230112, 1378, error A/B, duration 2&lt;/P&gt;&lt;P&gt;3. 20230112, 1379, error A/B/D, duration 300&lt;/P&gt;&lt;P&gt;4. 20230112, 1379, error A/B, duration 4&lt;BR /&gt;&lt;BR /&gt;I want select 1,3&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 00:58:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630726#M219113</guid>
      <dc:creator>disasters</dc:creator>
      <dc:date>2023-02-14T00:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to select only one event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630730#M219115</link>
      <description>&lt;P&gt;How should Splunk know which events to display?&amp;nbsp; When does it choose the highest duration and when does it choose the first and third?&amp;nbsp; Computers need rules to follow.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 01:16:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630730#M219115</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-02-14T01:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to select only one event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630731#M219116</link>
      <description>&lt;P&gt;query&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=ddos&lt;BR /&gt;| rex field=_raw "(?&amp;lt;time&amp;gt;.*),(&amp;lt;alert_num&amp;gt;.*),(&amp;lt;error&amp;gt;.*),(&amp;lt;duration&amp;gt;.*)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;event&lt;/P&gt;&lt;P&gt;20230112, 1378, error A/B/C, duration 100&lt;/P&gt;&lt;P&gt;20230112, 1378, error A/B, duration 2&lt;/P&gt;&lt;P&gt;20230112, 1379, error A/B/D, duration 300&lt;/P&gt;&lt;P&gt;20230112, 1379, error A/B, duration 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then query&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=ddos&lt;BR /&gt;| rex field=_raw "(?&amp;lt;time&amp;gt;.*),(&amp;lt;alert_num&amp;gt;.*),(&amp;lt;error&amp;gt;.*),(&amp;lt;duration&amp;gt;.*)"&lt;/P&gt;&lt;P&gt;| eventstats max(duration) as maxDuration&lt;/P&gt;&lt;P&gt;| where duration=maxDuration&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;event (only 1)&lt;/P&gt;&lt;P&gt;20230112, 1379, error A/B/D, duration 300&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to display two event that&amp;nbsp;&lt;SPAN&gt;different alert_num&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;20230112, 1378, error A/B/C, duration 100&lt;/P&gt;&lt;P&gt;20230112, 1379, error A/B/D, duration 300&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 01:40:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630731#M219116</guid>
      <dc:creator>disasters</dc:creator>
      <dc:date>2023-02-14T01:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to select only one event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630732#M219117</link>
      <description>&lt;P&gt;It works. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but same problem i have. Please refer to above reply.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 01:42:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630732#M219117</guid>
      <dc:creator>disasters</dc:creator>
      <dc:date>2023-02-14T01:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to select only one event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630734#M219118</link>
      <description>&lt;P&gt;Your rex statement is wrong and even when fixed, it extracts duration as the string&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;duration 300&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i.e. the full text, so you should use this rex&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw "(?&amp;lt;time&amp;gt;.*),(?&amp;lt;alert_num&amp;gt;.*),(?&amp;lt;error&amp;gt;.*),\s?duration\s+(?&amp;lt;duration&amp;gt;\d+)"
| eventstats max(duration) as maxDuration by alert_num
| where duration=maxDuration&lt;/LI-CODE&gt;&lt;P&gt;so your duration field is extracted as a number rather than a string. Then simply add the&amp;nbsp;&lt;STRONG&gt;by alert_num&lt;/STRONG&gt; onto your eventstats.&lt;/P&gt;&lt;P&gt;Note that you should still make your regex more robust. Using a greedy .* wildcard selection can easily cause your regex to break. For example as you know your field delimiter is a comma, use&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw "(?&amp;lt;time&amp;gt;[^,]*),(?&amp;lt;alert_num&amp;gt;[^,]),(?&amp;lt;error&amp;gt;[^,]),\s?duration\s+(?&amp;lt;duration&amp;gt;\d+)"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 04:16:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-select-only-one-event/m-p/630734#M219118</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-14T04:16:39Z</dc:date>
    </item>
  </channel>
</rss>

