<?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 How do you pull field values from an outer query to show in final table where inner query uses the map command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431471#M123330</link>
    <description>&lt;P&gt;I have a log file from which I extract the below table of test results, where each test result row describes a particular test status (PASS OR FAIL) and shows test start and end times.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Action      Status      startTime               endTime

    TEST_1      Success     1540031963.935      1540032192.644
    TEST_2      Success     1540030901.177      1540031831.031
    TEST_3      Success     1540030639.272      1540030890.771
    TEST_4      Success     1540030498.098      1540030628.755
    TEST_5      Success     1540030046.730      1540030487.604
    TEST_6      Fail               1540028918.752       1540030040.026
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For each test result or row, I would like to show a count for number of exceptions encountered during that test that is between start and end time for that test and be able to disable table as such: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Action      Status      startTime       endTime         ExceptionCount

TEST_1      Success     1540031963.935      1540032192.644      10
TEST_2      Success     1540030901.177      1540031831.031      20
TEST_3      Success     1540030639.272      1540030890.771      0
TEST_4      Success     1540030498.098      1540030628.755      1
TEST_5      Success     1540030046.730      1540030487.604      0
TEST_6      Fail                1540028918.752      1540030040.026      15
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I use the map command to iterate over each row/test result and use the &lt;CODE&gt;rex&lt;/CODE&gt; command to parse and count exceptions between earliest and latest whose values come from the row's start and end times. This is working but I don't know how to pull in the value of Action and Status field from the outer query. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index=myIndex host=abc sourcetype=AbcServer source="/opt/*"   "Test Result:" | rex .*"Action: "(?\w+).*", Test Result: "(?\w+).*", Start Time: "(?\d+\.\d+)", End Time: "(?\d+\.\d+) 
    | table Action Status startTime endTime 
    | map maxsearches=1000 search="search index=myIndex host=abc  sourcetype=AbcServer earliest=$startTime$ latest=$endTime$ *Exception | rex .*\": (?[\w\.]*Exception)\" 
    | stats count(exceptionClass) as CNT" 
    | table Action Status CNT
Action      Status      CNT

                                10
                                20
                                0
                                1
                                0
                                 15
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any thoughts on how to get Action and Status values into final result?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sat, 20 Oct 2018 11:27:56 GMT</pubDate>
    <dc:creator>bobkaz</dc:creator>
    <dc:date>2018-10-20T11:27:56Z</dc:date>
    <item>
      <title>How do you pull field values from an outer query to show in final table where inner query uses the map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431471#M123330</link>
      <description>&lt;P&gt;I have a log file from which I extract the below table of test results, where each test result row describes a particular test status (PASS OR FAIL) and shows test start and end times.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Action      Status      startTime               endTime

    TEST_1      Success     1540031963.935      1540032192.644
    TEST_2      Success     1540030901.177      1540031831.031
    TEST_3      Success     1540030639.272      1540030890.771
    TEST_4      Success     1540030498.098      1540030628.755
    TEST_5      Success     1540030046.730      1540030487.604
    TEST_6      Fail               1540028918.752       1540030040.026
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For each test result or row, I would like to show a count for number of exceptions encountered during that test that is between start and end time for that test and be able to disable table as such: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Action      Status      startTime       endTime         ExceptionCount

TEST_1      Success     1540031963.935      1540032192.644      10
TEST_2      Success     1540030901.177      1540031831.031      20
TEST_3      Success     1540030639.272      1540030890.771      0
TEST_4      Success     1540030498.098      1540030628.755      1
TEST_5      Success     1540030046.730      1540030487.604      0
TEST_6      Fail                1540028918.752      1540030040.026      15
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I use the map command to iterate over each row/test result and use the &lt;CODE&gt;rex&lt;/CODE&gt; command to parse and count exceptions between earliest and latest whose values come from the row's start and end times. This is working but I don't know how to pull in the value of Action and Status field from the outer query. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index=myIndex host=abc sourcetype=AbcServer source="/opt/*"   "Test Result:" | rex .*"Action: "(?\w+).*", Test Result: "(?\w+).*", Start Time: "(?\d+\.\d+)", End Time: "(?\d+\.\d+) 
    | table Action Status startTime endTime 
    | map maxsearches=1000 search="search index=myIndex host=abc  sourcetype=AbcServer earliest=$startTime$ latest=$endTime$ *Exception | rex .*\": (?[\w\.]*Exception)\" 
    | stats count(exceptionClass) as CNT" 
    | table Action Status CNT
Action      Status      CNT

                                10
                                20
                                0
                                1
                                0
                                 15
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any thoughts on how to get Action and Status values into final result?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 11:27:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431471#M123330</guid>
      <dc:creator>bobkaz</dc:creator>
      <dc:date>2018-10-20T11:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do you pull field values from an outer query to show in final table where inner query uses the map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431472#M123331</link>
      <description>&lt;P&gt;@bobkaz , you can try using Action and Status in the map command like the following and perform the stats by the two fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval Action=\"$Action$\", Status=\"$Status$\"
 | stats count(exceptionClass) as CNT" by Action Status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the one SPL based on existing search ( I think some of the characters in your post do not show up as expected).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=myIndex host=abc sourcetype=AbcServer source="/opt/*"   "Test Result:" | rex .*"Action: "(?\w+).*", Test Result: "(?\w+).*", Start Time: "(?\d+\.\d+)", End Time: "(?\d+\.\d+) 
 | table Action Status startTime endTime 
 | map maxsearches=1000 search="search index=myIndex host=abc  sourcetype=AbcServer earliest=$startTime$ latest=$endTime$ *Exception | rex .*\": (?[\w\.]*Exception)\"
 | eval Action=\"$Action$\", Status=\"$Status$\"
 | stats count(exceptionClass) as CNT" by Action Status
 | table Action Status CNT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, do give sample events for Exceptions corresponding to a test case so that we can assist you with any other approach as map could be an expensive command for correlation your use case.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 15:31:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431472#M123331</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-10-21T15:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do you pull field values from an outer query to show in final table where inner query uses the map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431473#M123332</link>
      <description>&lt;P&gt;Hi niketnilay,&lt;/P&gt;

&lt;P&gt;Thanks for your suggestion, I tweaked my SPL accordingly and it now runs successfully. However, when I add it to a statistics panel in the dashboard, it doesn't run and keeps saying "waiting for input", see attached picture.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;SPL:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=nsplogs host=hostA sourcetype=serverLog source="/opt/*"  "Test Result:" 
  | rex .*"Action: "(?\w+).*", Test Result: "(?\w+).*", Start Time: "(?\d+\.\d+)", End Time: "(?(\d+\.\d+)).*  
  | table Action Status startTime endTime 
  | map maxsearches=1000 search="search index=nsplogs host=hostB sourcetype=serverLog earliest=$startTime$ latest=$endTime$ *Exception 
  | rex .*\": (?[\w\.]*Exception)\" | eval Action=\"$Action$\", Status=\"$Status$\", startTime=\"$startTime$\", endTime=\"$endTime$\"
  | stats count(exceptionClass) as ExceptionCount by Action Status"
  | table Action Status ExceptionCount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that values of host attribute reflect real server names and aren't parametrized or are not tokens, so I don't know what input it is waiting for.&lt;/P&gt;

&lt;P&gt;Attached is a picture showing dashboard source code.&lt;/P&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5936i72A08B0AA66275AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5937i1C9DFFF3B2B8D272/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 14:25:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431473#M123332</guid>
      <dc:creator>bobkaz</dc:creator>
      <dc:date>2018-10-22T14:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do you pull field values from an outer query to show in final table where inner query uses the map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431474#M123333</link>
      <description>&lt;P&gt;Hi niketnilay,&lt;/P&gt;

&lt;P&gt;I figured out the problem. I had to replace every $ with $$ inside map command for SPL to work inside dashboard panel. Below is my working SPL:&lt;/P&gt;

&lt;P&gt;index=nsplogs host=hostA sourcetype=serverLog source="/opt/&lt;EM&gt;"  "Test Result:" &lt;BR /&gt;
   | rex .&lt;/EM&gt;"Action: "(?\w+).&lt;EM&gt;", Test Result: "(?\w+).&lt;/EM&gt;", Start Time: "(?\d+.\d+)", End Time: "(?(\d+.\d+)).*&lt;BR /&gt;&lt;BR /&gt;
   | table Action Status startTime endTime &lt;BR /&gt;
   | map maxsearches=1000 search="search index=nsplogs host=hostB sourcetype=serverLog earliest=$$startTime$$ latest=$$endTime$$ &lt;EM&gt;Exception &lt;BR /&gt;
   | rex .&lt;/EM&gt;\": (?[\w.]*Exception)\" | eval Action=\"$$Action$$\", Status=\"$$Status$$\", startTime=\"$$startTime$$\", endTime=\"$$endTime$$\"&lt;BR /&gt;
   | stats count(exceptionClass) as ExceptionCount by Action Status"&lt;BR /&gt;
   | table Action Status ExceptionCount&lt;/P&gt;

&lt;P&gt;Thanks a lot for your help, truly appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 04:55:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431474#M123333</guid>
      <dc:creator>bobkaz</dc:creator>
      <dc:date>2018-10-24T04:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do you pull field values from an outer query to show in final table where inner query uses the map command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431475#M123334</link>
      <description>&lt;P&gt;@bobkaz, the &lt;CODE&gt;$&lt;/CODE&gt; in the map command needs to be escaped in dashboard by prefixing with another &lt;CODE&gt;$&lt;/CODE&gt; sign. Refer to one of my previous answers: &lt;A href="https://answers.splunk.com/answers/680801/why-is-the-search-using-map-wont-work-in-dashboard.html"&gt;https://answers.splunk.com/answers/680801/why-is-the-search-using-map-wont-work-in-dashboard.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Please try out and confirm! Do up vote if it helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 05:19:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-pull-field-values-from-an-outer-query-to-show-in/m-p/431475#M123334</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-10-24T05:19:02Z</dc:date>
    </item>
  </channel>
</rss>

