<?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 to get a variable from first search and pass to subsearch? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248745#M74278</link>
    <description>&lt;P&gt;There are 2 kinds of log:&lt;BR /&gt;
one is error log&lt;BR /&gt;
the other is access log.&lt;/P&gt;

&lt;P&gt;In error log, there is a field &lt;CODE&gt;requestUrl&lt;/CODE&gt;. value format is &lt;CODE&gt;&lt;A href="https://google.com/home.html" target="test_blank"&gt;https://google.com/home.html&lt;/A&gt;&lt;/CODE&gt;.&lt;BR /&gt;
In access log, there is field &lt;CODE&gt;requestPath&lt;/CODE&gt;, value format is &lt;CODE&gt;/home.html&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I want to combine them with &lt;CODE&gt;requestUrl&lt;/CODE&gt; and &lt;CODE&gt;requestPath&lt;/CODE&gt;, and then count the error rate.&lt;/P&gt;

&lt;P&gt;The query I used likes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app..eventName=xxx| rex field=requestUrl "https://google.com(?&amp;lt;**path**&amp;gt;.*)" | stats count as failureCount | appendcols [search index=app .. requestPath=$**path**$| stats count as total]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The variable &lt;CODE&gt;**path**&lt;/CODE&gt; cannot be passed to &lt;CODE&gt;requestPath&lt;/CODE&gt; in &lt;CODE&gt;subsearch&lt;/CODE&gt;. I can only get &lt;CODE&gt;total=0&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Anyone know how to get the &lt;CODE&gt;path&lt;/CODE&gt; from the first search passed to subsearch?&lt;/P&gt;</description>
    <pubDate>Mon, 23 Nov 2015 11:11:47 GMT</pubDate>
    <dc:creator>amylala</dc:creator>
    <dc:date>2015-11-23T11:11:47Z</dc:date>
    <item>
      <title>How to get a variable from first search and pass to subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248745#M74278</link>
      <description>&lt;P&gt;There are 2 kinds of log:&lt;BR /&gt;
one is error log&lt;BR /&gt;
the other is access log.&lt;/P&gt;

&lt;P&gt;In error log, there is a field &lt;CODE&gt;requestUrl&lt;/CODE&gt;. value format is &lt;CODE&gt;&lt;A href="https://google.com/home.html" target="test_blank"&gt;https://google.com/home.html&lt;/A&gt;&lt;/CODE&gt;.&lt;BR /&gt;
In access log, there is field &lt;CODE&gt;requestPath&lt;/CODE&gt;, value format is &lt;CODE&gt;/home.html&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I want to combine them with &lt;CODE&gt;requestUrl&lt;/CODE&gt; and &lt;CODE&gt;requestPath&lt;/CODE&gt;, and then count the error rate.&lt;/P&gt;

&lt;P&gt;The query I used likes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app..eventName=xxx| rex field=requestUrl "https://google.com(?&amp;lt;**path**&amp;gt;.*)" | stats count as failureCount | appendcols [search index=app .. requestPath=$**path**$| stats count as total]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The variable &lt;CODE&gt;**path**&lt;/CODE&gt; cannot be passed to &lt;CODE&gt;requestPath&lt;/CODE&gt; in &lt;CODE&gt;subsearch&lt;/CODE&gt;. I can only get &lt;CODE&gt;total=0&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Anyone know how to get the &lt;CODE&gt;path&lt;/CODE&gt; from the first search passed to subsearch?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 11:11:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248745#M74278</guid>
      <dc:creator>amylala</dc:creator>
      <dc:date>2015-11-23T11:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a variable from first search and pass to subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248746#M74279</link>
      <description>&lt;P&gt;You may be better off doing this backwards. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=app [index=app..eventName=xxx| rex field=requestUrl "https://google.com(?.*)" |fields requestPath] &lt;BR /&gt;
  |stats count as Total count(eval(eventName="xxx")) as Failures by requestPath&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 12:36:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248746#M74279</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2015-11-23T12:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a variable from first search and pass to subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248747#M74280</link>
      <description>&lt;P&gt;Generally, this is done with the &lt;CODE&gt;map&lt;/CODE&gt; command but that would be way too inefficient for this use-case.&lt;/P&gt;

&lt;P&gt;Try this (put your special stuff instead of &lt;CODE&gt;...&lt;/CODE&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app ... | rex field=requestUrl "([^/]+://)?[^/]+(?&amp;lt;commonPath&amp;gt;/.*)"
| eval commonPath=coalesce(commonPath, requestPath)
| stats count(eval(isnotnull(requestUrl))) AS numErrors count(eval(isnotnull(requestPathl))) AS numHits by commonPath
| where numErrors&amp;gt;0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This shows you only those &lt;CODE&gt;path&lt;/CODE&gt; values that have errors and shows both a hit-count and error-count.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 21:47:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248747#M74280</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-27T21:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a variable from first search and pass to subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248748#M74281</link>
      <description>&lt;P&gt;Thanks jplumsdaine22 &amp;amp; woodcock. &lt;BR /&gt;
I cannot use requestUrl/eventName to count numErrors directly. I need to filter errors with other fields, like level=error. And this field exists only in event log not in access log.&lt;/P&gt;

&lt;P&gt;So I decide to use map command even it is inefficient. Thanks for your help. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2015 04:30:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248748#M74281</guid>
      <dc:creator>amylala</dc:creator>
      <dc:date>2015-11-30T04:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a variable from first search and pass to subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248749#M74282</link>
      <description>&lt;P&gt;I use following query. It works if base search result is not null. But get error if base search result is null - Error in 'map': Did not find value for required attribute 'commonPath'.&lt;BR /&gt;
What can I do to skip the subsearch and set &lt;CODE&gt;successRate&lt;/CODE&gt; to &lt;CODE&gt;100&lt;/CODE&gt; when no &lt;CODE&gt;numError&lt;/CODE&gt;?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app .. eventName=xxx| rex field=requestUrl "([^/]+://)?[^/]+(?/.*)" |stats count as numError by commonPath| map search="search index=app .. requestPath=$commonPath$| stats count as total by requestPath | eval successRate=(numTotal - $numError$)/numTotal*100 "
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Nov 2015 10:41:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248749#M74282</guid>
      <dc:creator>amylala</dc:creator>
      <dc:date>2015-11-30T10:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a variable from first search and pass to subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248750#M74283</link>
      <description>&lt;P&gt;Also, you cannot use asterisks ( * ) in a field name. Maybe that is the only problem that you are having?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 02:39:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-variable-from-first-search-and-pass-to-subsearch/m-p/248750#M74283</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-12-14T02:39:15Z</dc:date>
    </item>
  </channel>
</rss>

