<?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 trigger search based on a dynamic dropdown input? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372056#M109466</link>
    <description>&lt;P&gt;Whoa that was a lot more advanced than I expected &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I was doing some reading and found out about the format command which sounds like it could be of some use as well. I'll give it a try, thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2017 22:11:44 GMT</pubDate>
    <dc:creator>ByteFlinger</dc:creator>
    <dc:date>2017-03-23T22:11:44Z</dc:date>
    <item>
      <title>How to trigger search based on a dynamic dropdown input?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372052#M109462</link>
      <description>&lt;P&gt;I am trying to create a dropdown box to allow the user to select a host category (Like backend or frontend) and then I want to create another dropdown box to select a specific host.&lt;/P&gt;

&lt;P&gt;So far I have the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;input type="dropdown" token="product" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select category&amp;lt;/label&amp;gt;
      &amp;lt;choice value="*"&amp;gt;*&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;prefix&amp;gt;category="&amp;lt;/prefix&amp;gt;
      &amp;lt;suffix&amp;gt;"&amp;lt;/suffix&amp;gt;
      &amp;lt;change&amp;gt;
        &amp;lt;unset token="form.host"&amp;gt;&amp;lt;/unset&amp;gt;
      &amp;lt;/change&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| inputlookup host_table | stats count by category&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;category&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;category&amp;lt;/fieldForValue&amp;gt;
    &amp;lt;/input&amp;gt;
    &amp;lt;input type="dropdown" token="color" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select Color&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;sourcetype = "somesourcetype" [| inputlookup category | search $category$ | fields host ] | stats count by host&amp;lt;/query&amp;gt;
        &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;host&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;host&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;choice value="*"&amp;gt;*&amp;lt;/choice&amp;gt;
    &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That is followed by a graph which makes a simple search to show an event count for a specific log in that host&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="somesourcetype" host=$host$ | rex field=source max_match=40 ".*/(?&amp;lt;appname&amp;gt;.+)\.log" | timechart count by appname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So the idea here is that when the user changes a category, it will reset the host dropdown box since each category will have different hosts, setting it to &lt;CODE&gt;*&lt;/CODE&gt; so all hosts for that category are chosen by default and shown in the graph.&lt;/P&gt;

&lt;P&gt;This works well if the host dropdown has a specific host selected and the user changes the category however the issue I am having is if the host dropdown is &lt;CODE&gt;*&lt;/CODE&gt;, changing the category dropdown to any value (frontend, backend or *) will not change the graphs (But will properly repopulate the host dropdown with only the hosts available for that category).&lt;/P&gt;

&lt;P&gt;Does anybody knows why this happens and how to fix it?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 20:19:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372052#M109462</guid>
      <dc:creator>ByteFlinger</dc:creator>
      <dc:date>2017-03-23T20:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger search based on a dynamic dropdown input?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372053#M109463</link>
      <description>&lt;P&gt;Change your panel search like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="somesourcetype" [| inputlookup category | search $category$ AND  host=$host$  | fields host ]  | rex field=source max_match=40 ".*/(?&amp;lt;appname&amp;gt;.+)\.log" | timechart count by appname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you select &lt;CODE&gt;*&lt;/CODE&gt; , the panel search can't differentiate based on category, so need to add logic that will take both category and host dropdown value into consideration.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 21:11:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372053#M109463</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-23T21:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger search based on a dynamic dropdown input?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372054#M109464</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;

&lt;P&gt;I suspected this was the issue however the problem is that category is just a value in a lookup table and not something mapped to the actual host.&lt;/P&gt;

&lt;P&gt;I am quite new to Splunk and I am not even certain yet how to go about creating such a category to host mapping (maybe the Splunk forwarder could send this information in each server?) so for now I created a simple static lookup table with the mapping between category and host.&lt;/P&gt;

&lt;P&gt;With that lookup table the way I see to solve this would be to map the "*" value in the host dropdown to a dynamically generated query which returns a list of the hosts for that category. Something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(host="host1" OR host="host2")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which I could inject in the panel query however I have no idea how to go about generating such a query from a list of hosts. Any pointers?&lt;/P&gt;

&lt;P&gt;Any feedback would be welcome.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 21:38:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372054#M109464</guid>
      <dc:creator>ByteFlinger</dc:creator>
      <dc:date>2017-03-23T21:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger search based on a dynamic dropdown input?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372055#M109465</link>
      <description>&lt;P&gt;It might not work very well if the number of hosts are too big. But give this a try (xml code for host dropdown, replace your current query with tstats which is more efficient for this kind of query i.e. querying based on metadata like host/source/sourcetype etc.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   &amp;lt;label&amp;gt;Select Color&amp;lt;/label&amp;gt;
   &amp;lt;search&amp;gt;
     &amp;lt;query&amp;gt;| tstats count WHERE sourcetype = "somesourcetype" [| inputlookup category | search $category$ | fields host ]  by host | table host | eval hostvalue="host=".host | appendpipe [| stats values(hostvalue) as search | format | rename search as hostvalue | eval host="*" ]&amp;lt;/query&amp;gt;
     &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
   &amp;lt;/search&amp;gt;
   &amp;lt;fieldForLabel&amp;gt;host&amp;lt;/fieldForLabel&amp;gt;
   &amp;lt;fieldForValue&amp;gt;hostvalue&amp;lt;/fieldForValue&amp;gt;
   &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;      
 &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now your panel search will become this (instead of using host=$host$, you should be using just $host$ now)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="somesourcetype" $host$  | rex field=source max_match=40 ".*/(?&amp;lt;appname&amp;gt;.+)\.log" | timechart count by appname
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 21:49:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372055#M109465</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-23T21:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger search based on a dynamic dropdown input?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372056#M109466</link>
      <description>&lt;P&gt;Whoa that was a lot more advanced than I expected &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I was doing some reading and found out about the format command which sounds like it could be of some use as well. I'll give it a try, thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 22:11:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372056#M109466</guid>
      <dc:creator>ByteFlinger</dc:creator>
      <dc:date>2017-03-23T22:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger search based on a dynamic dropdown input?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372057#M109467</link>
      <description>&lt;P&gt;So after a bit of debugging I arrived at slightly different query than your&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE sourcetype = "somesourcetype" [| inputlookup category | search $category$ | fields host ]  by host | table host | eval hostvalue="host=".host | appendpipe [| table host | format | rename search as hostvalue | eval host="*" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Yours wraps the entire host query in quotes &lt;CODE&gt;(("host=host1") OR ("host=host2"))&lt;/CODE&gt; instead of &lt;CODE&gt;((host="host1") OR (host="host2"))&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So now the host dropdown returns the correct query but I am back at the original issue. Changing the category dropdown unsets the host dropdown which looks like in splunk terms it means to set it to the dropdown default value (Which I have as *) and this apparently leads to $hosts$ listing all servers&lt;/P&gt;

&lt;P&gt;I am able to confirm by creating a graph with the following query to simply list the current hosts&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="somesourcetype" $host$ | stats count by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Am I missing something? Does it have anything to do with the unset trigger maybe?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 17:30:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372057#M109467</guid>
      <dc:creator>ByteFlinger</dc:creator>
      <dc:date>2017-03-24T17:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to trigger search based on a dynamic dropdown input?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372058#M109468</link>
      <description>&lt;P&gt;Nope. I removed the  trigger from the category dropdown and it seems that the host dropdown is still updated when I change it (Which is nice) but the graphs still do not update on category changes if the host was * before the change&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:14:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-trigger-search-based-on-a-dynamic-dropdown-input/m-p/372058#M109468</guid>
      <dc:creator>ByteFlinger</dc:creator>
      <dc:date>2017-03-24T18:14:48Z</dc:date>
    </item>
  </channel>
</rss>

