Splunk Search

Want to condition match when a value is a single asterisk

simpkins1958
Contributor

Have tried every combination I can think of. Want to set some tokens in a when the value is a single asterisk.

As an exampl this does not work. The condition is matched for everything but a blank field.

<condition match="match(userSearchToken,&quot;\*&quot;)">
0 Karma

simpkins1958
Contributor

Was able to get it working with this XML:

    </input>
     <input type="text" token="deviceToken" searchWhenChanged="true">
       <label>Device:</label>
       <default>*</default>
       <change>
           <condition match="$value$==&quot;*&quot;">
             <set token="filterDeviceToken"></set>
           </condition>
           <condition>
             <set token="filterDeviceToken">nmds_app_dest_survey.d_name=$value|s$</set>
           </condition> 
       </change>      
     </input>

elliotproebstel
Champion

How about this structure instead:

    <input type="text" token="deviceSearchToken" searchWhenChanged="true">
      <label>Device:</label>
      <default>*</default>
      <change>
        <eval token="filterDeviceToken">if($deviceSearchToken$="*", "ASTERISK", "NOT ASTERISK")</eval>
        <eval token="deviceDrilldownToken">if($deviceSearchToken$="*", "ASTERISK2", "NOT ASTERISK2")</eval>
      </change>
    </input>

You'll need to replace "ASTERISK"/"NOT ASTERISK" with the values you actually want to use there, but I'm confused about what your intentions are for those, as the structure you're using inside the <set> elements above isn't really clear to me.

0 Karma

elliotproebstel
Champion

Here's a full test dashboard that you could use to validate:

<form>
  <label>test_match</label>
  <fieldset submitButton="false">
    <input type="text" token="deviceSearchToken" searchWhenChanged="true">
      <label>Device:</label>
      <default>*</default>
      <change>
        <eval token="filterDeviceToken">if($deviceSearchToken$="*", "ASTERISK", "NOT ASTERISK")</eval>
        <eval token="deviceDrilldownToken">if($deviceSearchToken$="*", "ASTERISK2", "NOT ASTERISK2")</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <search>
          <query>| stats count | eval first="$filterDeviceToken$", second="$deviceDrilldownToken$"</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>
0 Karma

Kenshiro70
Path Finder

You might want to consider changing $filterDeviceToken$ to $value$. If prefix or suffix is defined, the full token will include them, whereas the value token will return only what's in the input.

0 Karma

simpkins1958
Contributor

Here is a complete example that is not working. When enter a value that is not a single asterisk the match still executes.

    <input type="text" token="deviceSearchToken" searchWhenChanged="true">
      <label>Device:</label>
      <default>*</default>
        <change>
          <condition match="match(deviceSearchToken, &quot;&#92;*&quot;)">
            <set token="filterDeviceToken"></set>
            <set token="deviceDrilldownToken"></set>
          </condition>
          <condition>
            <set token="filterDeviceToken">nmds_app_dest_survey.d_name=$value|s$</set>
            <set token="deviceDrilldownToken">&amp;form.deviceToken=$value|u$</set>            
          </condition>
        </change>      
    </input>
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...