<?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 run a search only if the panel is visible in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474687#M133484</link>
    <description>&lt;P&gt;depends only affects the visibility of the panel. The query will run if it has everything it needs. To prevent this, you need to add the token to your search. &lt;/P&gt;

&lt;P&gt;Here's one way to achieve this .Lets say your panel depends on the token &lt;CODE&gt;$hidePanel$&lt;/CODE&gt; you can make the search execution dependent on this token by adding &lt;CODE&gt;|where $hidePanel$==$hidePanel$&lt;/CODE&gt; to the end of the query. The where clause will just resolve to  where True and won't filter your results&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel depends="$hidePanel$"&amp;gt;
      &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;|makeresults | where $hidePanel$==$hidePanel$&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Based on your scenario, there are multiple ways to achieve this.&lt;/P&gt;

&lt;P&gt;Hope this helps. Please Upvote and mark as answer if this is what you were looking for.&lt;/P&gt;

&lt;P&gt;Cheers.&lt;/P&gt;

&lt;P&gt;EDIT: Based on @niketnilay 's Tip, we can use the comment macro to eliminate the additional processing introduced by the where clause. Based on this, replacing the where clause with the comment macro&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel depends="$hidePanel$"&amp;gt;
      &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;|makeresults `comment("This search depends on $hidePanel$ for execution")`&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 03 Nov 2019 00:51:01 GMT</pubDate>
    <dc:creator>arjunpkishore5</dc:creator>
    <dc:date>2019-11-03T00:51:01Z</dc:date>
    <item>
      <title>How to run a search only if the panel is visible</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474686#M133483</link>
      <description>&lt;P&gt;The panel depends is been ignored and is still running the query which causes performance issues. &lt;BR /&gt;
How can you only run a query if the panel is visible?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 07:50:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474686#M133483</guid>
      <dc:creator>jjwallaby</dc:creator>
      <dc:date>2019-11-02T07:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search only if the panel is visible</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474687#M133484</link>
      <description>&lt;P&gt;depends only affects the visibility of the panel. The query will run if it has everything it needs. To prevent this, you need to add the token to your search. &lt;/P&gt;

&lt;P&gt;Here's one way to achieve this .Lets say your panel depends on the token &lt;CODE&gt;$hidePanel$&lt;/CODE&gt; you can make the search execution dependent on this token by adding &lt;CODE&gt;|where $hidePanel$==$hidePanel$&lt;/CODE&gt; to the end of the query. The where clause will just resolve to  where True and won't filter your results&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel depends="$hidePanel$"&amp;gt;
      &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;|makeresults | where $hidePanel$==$hidePanel$&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Based on your scenario, there are multiple ways to achieve this.&lt;/P&gt;

&lt;P&gt;Hope this helps. Please Upvote and mark as answer if this is what you were looking for.&lt;/P&gt;

&lt;P&gt;Cheers.&lt;/P&gt;

&lt;P&gt;EDIT: Based on @niketnilay 's Tip, we can use the comment macro to eliminate the additional processing introduced by the where clause. Based on this, replacing the where clause with the comment macro&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel depends="$hidePanel$"&amp;gt;
      &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;|makeresults `comment("This search depends on $hidePanel$ for execution")`&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Nov 2019 00:51:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474687#M133484</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-03T00:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search only if the panel is visible</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474688#M133485</link>
      <description>&lt;P&gt;Thanks for answering.&lt;/P&gt;

&lt;P&gt;Reasons you may have 10 panels&lt;BR /&gt;
Each panel may have 5 or more queries charts..etc&lt;BR /&gt;
So you want only &lt;BR /&gt;
Run query if you actually on panel.&lt;/P&gt;

&lt;P&gt;Otherwise performance is poor and wasting resources.&lt;/P&gt;

&lt;P&gt;I thought splunk would have this feature.&lt;/P&gt;

&lt;P&gt;Yes could convert and use js but that is last resort..as it is  ugly and messy.&lt;/P&gt;

&lt;P&gt;My question to you&lt;BR /&gt;
If put the where condition at end of query..it still uses resources on backend.&lt;/P&gt;

&lt;P&gt;Each query will take 1 process on backend..&lt;/P&gt;

&lt;P&gt;Therefore if you have total 10 queries per panel is 100 queries forked off to backend.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 01:50:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474688#M133485</guid>
      <dc:creator>jjwallaby</dc:creator>
      <dc:date>2019-11-03T01:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search only if the panel is visible</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474689#M133486</link>
      <description>&lt;P&gt;@arjunpkishore adding a search or where pipe for filtering results (whether it filters or not) implies it will be applied to all the events and return the same result as previous pipe. This means the dependency will impact query performance. Better approach is to use the &lt;CODE&gt;comment macro&lt;/CODE&gt; with dummy dependency on the token used in depends or in the worst case use inexpensive commands like &lt;CODE&gt;fields -&lt;/CODE&gt; with token for dummy dependency which does not perform any action when depenedent token is set.&lt;/P&gt;

&lt;P&gt;@jjwallaby refer to one of my older answer for similar situation with example: &lt;A href="https://answers.splunk.com/answers/683826/how-do-you-set-the-order-of-queries-to-be-run-in-a.html"&gt;https://answers.splunk.com/answers/683826/how-do-you-set-the-order-of-queries-to-be-run-in-a.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 08:07:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474689#M133486</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-11-03T08:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search only if the panel is visible</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474690#M133487</link>
      <description>&lt;P&gt;The comment macro is new to me. Thanks for the tip. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 14:12:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474690#M133487</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-03T14:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search only if the panel is visible</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474691#M133488</link>
      <description>&lt;P&gt;If you have a variable in the search, then the search is not executed till the variable has value. I have replaced the where clause with the comment macro as suggested by @niketnilay &lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 14:17:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-only-if-the-panel-is-visible/m-p/474691#M133488</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-03T14:17:31Z</dc:date>
    </item>
  </channel>
</rss>

