<?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: Dynamic Splunk Queries in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145290#M8807</link>
    <description>&lt;P&gt;I don't want to search the results of another search, I want to use a query to create a query.&lt;/P&gt;

&lt;P&gt;If you look at the above example, I set foo="index=main | head 10 | table src_ip dest_ip", I then when to execute the query index=main | head 10 | table src_ip dest_ip.  I would be more then happy to add the implicit search command to the beginning.&lt;/P&gt;

&lt;P&gt;I'm aware of sub-searches and have used them, but at least when ran as you listed above, I haven't been able to get them to do this.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 15:51:39 GMT</pubDate>
    <dc:creator>triest</dc:creator>
    <dc:date>2020-09-28T15:51:39Z</dc:date>
    <item>
      <title>Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145288#M8805</link>
      <description>&lt;P&gt;Is there a way to run a search command and have it return the text of a query to run?  &lt;/P&gt;

&lt;P&gt;E.g.  [ | gentimes start=-1 | eval foo="index=main | head 10 | table src_ip dest_ip" | fields foo | table foo ]&lt;/P&gt;

&lt;P&gt;Is there a way to get it to execute the query stored in foo above?&lt;/P&gt;

&lt;P&gt;The actual use case is I've written queries that are fairly complex and I'd like to create macro's to use as templates.  I wrote queries that generate the query text out of laziness and I would love to turn them into macros that would "just do the right thing".&lt;/P&gt;

&lt;P&gt;It should be possible using the rest interface, but I'm hoping to avoid that.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145288#M8805</guid>
      <dc:creator>triest</dc:creator>
      <dc:date>2020-09-28T15:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145289#M8806</link>
      <description>&lt;P&gt;Hi triest,&lt;/P&gt;

&lt;P&gt;If I understand it correct you want to search for the result of another search? It so, you can use a &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.1/Search/Usesubsearchtocorrelateevents"&gt;subsearch&lt;/A&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YourMasterSearch [ search gentimes start=-1 | eval foo="index=main | head 10 | table src_ip dest_ip" | fields foo | table foo ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;First, this will run the search in &lt;CODE&gt;[]&lt;/CODE&gt; and the results will be used in &lt;CODE&gt;YourMasterSearch&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 07:16:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145289#M8806</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-02-11T07:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145290#M8807</link>
      <description>&lt;P&gt;I don't want to search the results of another search, I want to use a query to create a query.&lt;/P&gt;

&lt;P&gt;If you look at the above example, I set foo="index=main | head 10 | table src_ip dest_ip", I then when to execute the query index=main | head 10 | table src_ip dest_ip.  I would be more then happy to add the implicit search command to the beginning.&lt;/P&gt;

&lt;P&gt;I'm aware of sub-searches and have used them, but at least when ran as you listed above, I haven't been able to get them to do this.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:51:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145290#M8807</guid>
      <dc:creator>triest</dc:creator>
      <dc:date>2020-09-28T15:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145291#M8808</link>
      <description>&lt;P&gt;Well sorry in this case, I got you wrong. And my example will not work because of this &lt;CODE&gt;eval foo&lt;/CODE&gt; which will not work. I use some macros but more the other way round. The macro contains the main search and I pass values to it like &lt;CODE&gt;myMacro(foo)&lt;/CODE&gt; where &lt;CODE&gt;myMacro&lt;/CODE&gt; is some search and &lt;CODE&gt;foo&lt;/CODE&gt; is used in this search.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 12:04:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145291#M8808</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-02-11T12:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145292#M8809</link>
      <description>&lt;P&gt;I am not sure its possible without REST APIs. One of the closest solution I figured (but sadly it didn't work)(subsearch or macro search).&lt;/P&gt;

&lt;P&gt;[search * | head 1 | eval search="Your query here"| table search | format]&lt;/P&gt;

&lt;P&gt;The only problem that I got was that the value will come as "&lt;EM&gt;Your query here&lt;/EM&gt;" which doesn't work if there is a space there.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 14:36:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145292#M8809</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-02-11T14:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145293#M8810</link>
      <description>&lt;P&gt;Tonight I'll look into how to do it with the rest API's then; if some one beats me to it with a solution, I wouldn't complain &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 16:21:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145293#M8810</guid>
      <dc:creator>triest</dc:creator>
      <dc:date>2014-02-11T16:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145294#M8811</link>
      <description>&lt;P&gt;Your best chance to achieve this without diving into APIs probably would have been the &lt;CODE&gt;map&lt;/CODE&gt; command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval mysearchstring="search earliest=-2h@h latest=@h index=_internal log_level=ERROR) | timechart count by sourcetype" | map search="$mysearchstring$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, that wraps the generated query in quotes and escapes quotes within the query, so you can't break out of that.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2014 20:37:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145294#M8811</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-02-11T20:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145295#M8812</link>
      <description>&lt;P&gt;So just found this question, and was surprised to see that this &lt;STRONG&gt;almost&lt;/STRONG&gt; works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ | stats count | eval s="index=main | head 1" | return $s ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's totally wacky to mean that Splunk lets you pass a "|" to the search and execute it like this.   I said "almost worked" because I end up with 3 results, which it turns out is because the environment I tested it on had 3 indexers.  Changed it to "head 5" and got back 15 results.&lt;/P&gt;

&lt;P&gt;Interesting.  Tested on a 6.2.6 environment.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 22:20:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145295#M8812</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2016-01-28T22:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145296#M8813</link>
      <description>&lt;P&gt;Nice! forgot about this one and can add another solution which is working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ | gentimes start=-1 | eval foo="index=_internal | head 10 " | fields foo | rename foo -&amp;gt; search ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;rund this litsearch in the end:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=_internal | head 10 | fields keepcolorder=t "_bkt" "_cd" "_si" "host" "index" "linecount" "source" "sourcetype" "splunk_server"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2016 22:34:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145296#M8813</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-01-28T22:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Splunk Queries</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145297#M8814</link>
      <description>&lt;P&gt;@triest did you ever get it to work ? 2017 still having this problem &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 16:18:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Dynamic-Splunk-Queries/m-p/145297#M8814</guid>
      <dc:creator>theeansible</dc:creator>
      <dc:date>2017-09-22T16:18:37Z</dc:date>
    </item>
  </channel>
</rss>

