<?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 do I list data rows starting at a certain point if a field contains a particular value in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390576#M6551</link>
    <description>&lt;P&gt;So if your current search is selecting all data, regardless of where it has field1="alert" or not, all those will be selected by line 1. The events returned should be in reverse chronological order of _time (latest events first). The line 2 should add a field count on each events with 1,2,3.. untill it's find field1="alert". It'll reset the count to start from 1 again once it found field1="alert" and so on. The where clause should only select events with field="alert" and all subsequent rows which have count (or serial number) less than 51.&lt;BR /&gt;
Do you see different output from the query I suggested?&lt;/P&gt;</description>
    <pubDate>Mon, 14 May 2018 20:42:27 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-05-14T20:42:27Z</dc:date>
    <item>
      <title>How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390570#M6545</link>
      <description>&lt;P&gt;I've a need to search through some data for a field that has a particular value.   If the value is found, then I want to list out that line and the 50 lines that precedes it.&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;01)  Search sourcetype=abc for field1="alert". &lt;/P&gt;

&lt;P&gt;02)  Field1="alert" is first found at 2018-05-10 18:10:01&lt;/P&gt;

&lt;P&gt;03)  List out entry for 2018-05-10 18:10:01 and the 50 data entries prior/earlier then 18:10:01.  The 50 data entries may not be related to or contain field1="alert".  They are needed for review of activity leading to the "alert".&lt;/P&gt;

&lt;P&gt;04)  Field1="alert" is next found at  2018-04-27 13:57:55&lt;/P&gt;

&lt;P&gt;05)  List out entry for 2018-05-10 13:10:00 and the 50 data entries prior/earlier then 13:57:55.  The 50 data entries may not be related to or contain field1="alert".  They are needed for review of activity leading to the "alert".&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;I've tried several things unsuccessfully.  I could really use some guidance.&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 18:55:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390570#M6545</guid>
      <dc:creator>Gawker</dc:creator>
      <dc:date>2018-05-14T18:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390571#M6546</link>
      <description>&lt;P&gt;What version of Splunk are you using?&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 19:04:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390571#M6546</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-14T19:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390572#M6547</link>
      <description>&lt;P&gt;If you're using Splunk 6.4 or above, give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your current search querying sourcetype=abc and gets all events
| streamstats count reset_before="Field1=\"alert\""
| where count&amp;lt;=50
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 May 2018 19:39:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390572#M6547</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-14T19:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390573#M6548</link>
      <description>&lt;P&gt;Cloud based SaaS instance:  7.0.0.1 aef63c0828ae&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 19:52:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390573#M6548</guid>
      <dc:creator>Gawker</dc:creator>
      <dc:date>2018-05-14T19:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390574#M6549</link>
      <description>&lt;P&gt;Ok.. give the above query a try. &lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 20:02:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390574#M6549</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-14T20:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390575#M6550</link>
      <description>&lt;P&gt;For clarification, I updated my question.&lt;/P&gt;

&lt;P&gt;The 50 rows after the field1="alert" that I am interested in are not entries with "alert".   &lt;/P&gt;

&lt;P&gt;What I am looking for would be something akin to a head/tail combination of the data based on the actual time of the entry which contains field1="alert".  I want to capture the "alert" row and 50 data rows following it, regardless of the contents of the 50 rows.&lt;/P&gt;

&lt;P&gt;Hope that clarifies things.&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 20:23:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390575#M6550</guid>
      <dc:creator>Gawker</dc:creator>
      <dc:date>2018-05-14T20:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390576#M6551</link>
      <description>&lt;P&gt;So if your current search is selecting all data, regardless of where it has field1="alert" or not, all those will be selected by line 1. The events returned should be in reverse chronological order of _time (latest events first). The line 2 should add a field count on each events with 1,2,3.. untill it's find field1="alert". It'll reset the count to start from 1 again once it found field1="alert" and so on. The where clause should only select events with field="alert" and all subsequent rows which have count (or serial number) less than 51.&lt;BR /&gt;
Do you see different output from the query I suggested?&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 20:42:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390576#M6551</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-14T20:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390577#M6552</link>
      <description>&lt;P&gt;I took a small data source where verification of my search criteria and results would be easy.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;(01)&lt;/STRONG&gt; Here's the data from a specific time picker range that was convenient to use as there were only 12 events.&lt;/P&gt;

&lt;P&gt;"12 events (5/15/18 12:00:00.000 AM to 5/16/18 12:00:00.000 AM)"&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;grep "2018-05-15 15:32:" ../log/server.log&lt;/P&gt;

&lt;H1&gt;xxxxxxxx75&lt;/H1&gt;

&lt;H1&gt;xxxxxxxx78&lt;/H1&gt;

&lt;P&gt;grep exception ../log/server.log&lt;/P&gt;

&lt;H1&gt;xxxxxxxx66&lt;/H1&gt;

&lt;P&gt;tail -f ../log/server.log&lt;/P&gt;

&lt;H1&gt;xxxxxxxx66&lt;/H1&gt;

&lt;P&gt;cd /usr/local/jboss/server/default/deploy&lt;BR /&gt;
2018-05-15 11:34:16&lt;/P&gt;

&lt;H1&gt;xxxxxxxx99&lt;/H1&gt;

&lt;P&gt;nslookup eudc2.eu.ei3.local&lt;/P&gt;

&lt;H1&gt;xxxxxxxx94&lt;/H1&gt;

&lt;P&gt;nslookup xxxxx.xxxxxx.xxxxxx.xx&lt;/P&gt;

&lt;H1&gt;xxxxxxxx44&lt;/H1&gt;

&lt;P&gt;cat inputs.conf &lt;/P&gt;

&lt;H1&gt;xxxxxxxx43&lt;/H1&gt;

&lt;P&gt;ls&lt;/P&gt;

&lt;H1&gt;xxxxxxxx41&lt;/H1&gt;

&lt;P&gt;cd /opt/splunkforwarder/etc/system/local/&lt;BR /&gt;
2018-05-15 09:32:12&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;STRONG&gt;(02)&lt;/STRONG&gt;  I set up this query, using the date/time from the first event (see above) as my key for streamstats:&lt;/P&gt;

&lt;P&gt;source="/root/.bash_history" | rex "(grep \"(?.&lt;EM&gt;)\" ..\/log\/server.log)"  | streamstats count reset_after="Search_It=\"&lt;/EM&gt;&lt;STRONG&gt;2018-05-15 15:32:&lt;/STRONG&gt;*\"" | where count&amp;lt;=3&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;(03)&lt;/STRONG&gt;  The results from the aforementioned query and the time range picker yielded what was expected, the "key" entry and three rows:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;grep "2018-05-15 15:32:" ../log/server.log&lt;/P&gt;

&lt;H1&gt;xxxxxxxx75&lt;/H1&gt;

&lt;H1&gt;xxxxxxxx78&lt;/H1&gt;

&lt;P&gt;grep exception ../log/server.log&lt;/P&gt;

&lt;H1&gt;xxxxxxxx66&lt;/H1&gt;

&lt;P&gt;tail -f ../log/server.log&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;STRONG&gt;(04)&lt;/STRONG&gt;  I set  the time range picker to "All", which then yielded an extra row in addition to the 4 expected as in (03):&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;2018-05-17 16:49:01&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Any idea as to why the extra row shows up?&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:35:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390577#M6552</guid>
      <dc:creator>Gawker</dc:creator>
      <dc:date>2020-09-29T19:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list data rows starting at a certain point if a field contains a particular value</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390578#M6553</link>
      <description>&lt;P&gt;If field1 exists always but is only sometimes error, then ...&lt;/P&gt;

&lt;P&gt;Hmm.  There's several ways to do this (some outlined by the inestimable somesoni2 already).  Let's try this one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc
| eval is_error = if(field1=="error", "error", null())
| streamstats window=50 last(is_error) as trigger_error
| transaction maxevents=50 trigger_error
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That should create one "event" out of the error line, plus the preceeding 50 events.&lt;/P&gt;

&lt;P&gt;NOTES: &lt;BR /&gt;
&lt;STRONG&gt;Change&lt;/STRONG&gt; &lt;CODE&gt;window=50&lt;/CODE&gt; and &lt;CODE&gt;maxevents=50&lt;/CODE&gt; to 5 each for testing - it might make it easier to see/test.  They should match each other, but otherwise the number is up to you.&lt;BR /&gt;
&lt;STRONG&gt;Also&lt;/STRONG&gt;, for debugging it might be useful to run that same search only replace the &lt;CODE&gt;| transaction...&lt;/CODE&gt; line with  &lt;CODE&gt;| table _time, field1, is_error, trigger_error&lt;/CODE&gt; (and maybe include another field or two if it makes sense).  If you do that, you'll see better how it works.&lt;/P&gt;

&lt;P&gt;It works by &lt;BR /&gt;
a) searching &lt;EM&gt;all&lt;/EM&gt; the data - you can't throw out the non-error ones at the front or else how would you include them later?&lt;BR /&gt;&lt;BR /&gt;
b) creating a new field "is_error" (change that name if it conflicts with an existing field!) that only exists when field1 equals "error".  This way if field1 is NOT "error" then there's no new field "is_error" on that event.&lt;BR /&gt;&lt;BR /&gt;
c) now the magic - streamstats in this case is watching a window or 50 events.  For each event, it copies the most recent "is_error" to the all 50 events in its window as the field "trigger_error".  This means that when "is_error" doesn't exist, nothing gets copied, but when it does, the preceeding 50 events also get a copy of it.&lt;BR /&gt;&lt;BR /&gt;
d) last we just group them together to make it easy to alert on it.  &lt;/P&gt;

&lt;P&gt;Line d) may require a little fiddling depending on exactly how you are going to use this.  &lt;/P&gt;

&lt;P&gt;As reference, &lt;A href="https://answers.splunk.com/answers/310019/as-part-of-a-splunk-alert-is-it-possible-to-includ.html" target="_blank"&gt;here's a very similar thing done&lt;/A&gt; with 100 items before the "alerting event".  It's not quite the same scenario, but it is close enough that it may help to read through that answer too.&lt;/P&gt;

&lt;P&gt;Happy Splunking!&lt;BR /&gt;
-Rich&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:39:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-list-data-rows-starting-at-a-certain-point-if-a-field/m-p/390578#M6553</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2020-09-29T19:39:12Z</dc:date>
    </item>
  </channel>
</rss>

