<?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: Executing Conditional Queries in Splunk Based on Input Value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703187#M238362</link>
    <description>&lt;P&gt;Why don't you try with macros and if, case statement?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2024 18:03:16 GMT</pubDate>
    <dc:creator>alexandarmatev1</dc:creator>
    <dc:date>2024-10-30T18:03:16Z</dc:date>
    <item>
      <title>Executing Conditional Queries in Splunk Based on Input Value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703132#M238358</link>
      <description>&lt;P&gt;I have two query in splunk query 1 and query 2 and an input. Based on the input, i need to execute either query 1 or query 2. I am trying something like below query but it is not working for me.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval myInput="*"

| append [
search "my search related to query 1"
| rex field=_raw "Job id : (?&amp;lt;job_id&amp;gt;[^,]+)"
| where myInput="*"
| eval query_type="query1"
| table job_id, query_type, myInput
]
| append [
search "my search related to query 2"
| rex field=_raw "Job id : (?&amp;lt;job_id&amp;gt;[^,]+)"
| where myInput!="*"
| eval query_type="query2"
| table job_id, query_type, myInput
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 14:46:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703132#M238358</guid>
      <dc:creator>taruntalreja</dc:creator>
      <dc:date>2024-10-30T14:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Conditional Queries in Splunk Based on Input Value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703148#M238360</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults
| eval myInput="*"

| append [
    | search "my search related to query 1"
    | rex field=_raw "Job id : (?&amp;lt;job_id&amp;gt;[^,]+)"
    | eval query_type=if(myInput="*", "query1", null())
    | where query_type="query1"
    | table job_id, query_type, myInput
]

| append [
    | search "my search related to query 2"
    | rex field=_raw "Job id : (?&amp;lt;job_id&amp;gt;[^,]+)"
    | eval query_type=if(myInput!="*", "query2", null())
    | where query_type="query2"
    | table job_id, query_type, myInput
]&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 30 Oct 2024 16:54:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703148#M238360</guid>
      <dc:creator>alexandarmatev1</dc:creator>
      <dc:date>2024-10-30T16:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Conditional Queries in Splunk Based on Input Value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703151#M238361</link>
      <description>&lt;P&gt;This solution does not work, I am getting empty result. I think there is an issue and myInput variable is not passed in append. One more issue with this solution is that both the queries will be running but we know beforehand which query to run, so I am looking for some optimized solution where only 1 query is ran based on the filter.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 17:11:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703151#M238361</guid>
      <dc:creator>taruntalreja</dc:creator>
      <dc:date>2024-10-30T17:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Conditional Queries in Splunk Based on Input Value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703187#M238362</link>
      <description>&lt;P&gt;Why don't you try with macros and if, case statement?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 18:03:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703187#M238362</guid>
      <dc:creator>alexandarmatev1</dc:creator>
      <dc:date>2024-10-30T18:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Conditional Queries in Splunk Based on Input Value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703259#M238370</link>
      <description>&lt;P&gt;SPL does not support conditional execution of commands.&amp;nbsp; It can be simulated in a dashboard by setting a token to the desired search string and referencing the token in the query.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;fieldset&amp;gt;
  &amp;lt;input token="myInput"...&amp;gt;
    &amp;lt;change&amp;gt;
      &amp;lt;condition match="&amp;lt;&amp;lt;option 1&amp;gt;&amp;gt;"&amp;gt;
        &amp;lt;set token="query"&amp;gt;SPL for option 1&amp;lt;/set&amp;gt;
      &amp;lt;/condition&amp;gt;
      &amp;lt;condition match="&amp;lt;&amp;lt;option 2&amp;gt;&amp;gt;"&amp;gt;
        &amp;lt;set token="query"&amp;gt;SPL for option 2&amp;gt;&amp;lt;/set&amp;gt;
      &amp;lt;/condition&amp;gt;
    &amp;lt;/change&amp;gt;
  &amp;lt;/input&amp;gt;
&amp;lt;/fieldset&amp;gt;
...
&amp;lt;row&amp;gt;
  &amp;lt;panel&amp;gt;
    &amp;lt;table&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;$query$&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
    &amp;lt;/table&amp;gt;
  &amp;lt;/panel&amp;gt;
&amp;lt;/row&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 31 Oct 2024 13:14:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Executing-Conditional-Queries-in-Splunk-Based-on-Input-Value/m-p/703259#M238370</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2024-10-31T13:14:15Z</dc:date>
    </item>
  </channel>
</rss>

