Dashboards & Visualizations

How to use condition match to show a column when conditions match and omit the column when it doesn't in type dropdown ?

_pravin
Contributor

Hi All,

I am new to Splunk so I am not sure if I am doing this right.

For one of the use cases, I am trying to use a condition match in the type dropdown to make a column visible when the condition match and omit the column when it doesn't.

Below is the code I am using where I am creating a new token called cache_type_token and setting the value from the input token cache_type.

I am unable to understand if there's some issue with the token being set or the match condition.

 

<input type="dropdown" token="cache_type" searchWhenChanged="true">
<label>Choose which type of cache to view</label>
<choice value="*UTable-*">Utilisation Table</choice>
<choice value="ContextualLineCache*">Contextual Line Cache</choice>
<choice value="GlobalRuleCache*">Global Rule Cache</choice>
<choice value="RTLIM*">RTLIM</choice>
<choice value="BATCH*">BATCH</choice>
<choice value="COB*">COB</choice>
<choice value="EOM*">EOM</choice>
<choice value="*">ALL</choice>
<default>Utilisation Table</default>


<change>
<set token='cache_type_token'>$cache_type$</set>

<condition match=" $cache_type_token$ == &quot;ContextualLineCache*&quot; ">
<set token="cache_type_token">0</set>
</condition>

<condition match=" $cache_type_token$ != &quot;ContextualLineCache*&quot; ">
<set token="cache_type_token">cacheExpired</set>
</condition>
</change>

</input>

Labels (1)
0 Karma

rrovers
Contributor

I think you should use "eval token".

Here is a simplified example of your case:

<dashboard>
<label>Test</label>
<init>
<unset token="cache_type"></unset>
<unset token="cache_type_token"></unset>
</init>
<fieldset>
<input type="dropdown" token="cache_type" searchWhenChanged="true">
<change>
<condition match=" $cache_type$ == &quot;ContextualLineCache*&quot; ">
<eval token="cache_type_token">0</eval>
</condition>
<condition>
<eval token="cache_type_token">$cache_type$</eval>
</condition>
</change>
<label>Choose which type of cache to view</label>
<choice value="*UTable-*">Utilisation Table</choice>
<choice value="ContextualLineCache*">Contextual Line Cache</choice>
<choice value="GlobalRuleCache*">Global Rule Cache</choice>
<choice value="RTLIM*">RTLIM</choice>
<choice value="BATCH*">BATCH</choice>
<choice value="COB*">COB</choice>
<choice value="EOM*">EOM</choice>
<choice value="*">ALL</choice>
<default>Utilisation Table</default>

</input>
</fieldset>
<row>
<html>
cache_type: $cache_type$ cache_type_token: $cache_type_token$
</html>
</row>
</dashboard>

0 Karma

_pravin
Contributor

@rroversThanks for your response. Actually, I was able to figure out what went wrong.

I was setting the token wrong outside of the condition tags.

<change>
<condition match=" $cache_type$ == &quot;ContextualLineCache*&quot; ">
<eval token="cache_type_token">0</eval>
</condition>
<condition>
<eval token="cache_type_token">cacheExpired</eval>
</condition>
</change>

 

I even tried your code and realised that using eval doesn't set the token rather makes it undefined. Also, since I was making changes in the panel init tags didn't work. Thanks  again.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...