Dashboards & Visualizations
Highlighted

[Solved] Displaying a panel depending on a token OR another

Path Finder

Hi all,

I don't know if what I am asking is possible but I've got a Radio input with 3 choices:

[] CPU
[] Memory
[] CPU and Memory

I want to be able to show and hide panels depending on this choice. It's ok for CPU OR Memory input because it's only a depends="$showCpu$" or the other one for memory.

But when I want to display both I can't find the solution.

using depends="$showCpu$,$showMemory$" would expect both tokens to be set... it's a AND condition.

Is there any "OR" condition that I missed somewhere? do you see anything I could do to solve this please?

Thanks in advance for your help guys!

Laurent

0 Karma
Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

SplunkTrust
SplunkTrust

Hi

There is no OR in depends but yes you can in another way.
You can set and unset another token for your use case. see below XML code.

  <label>Radio</label>
  <choice value="CPU">CPU</choice>
  <choice value="Memory">Memory</choice>
  <choice value="Disk">Disk</choice>
  <change>
    <condition match="match('value',&quot;CPU&quot;)">
      <set token="CPU">True</set>
      <unset token="Memory" />
      <unset token="Disk" />
      <set token="CPU_Memory">True</set>
    </condition>
    <condition match="match('value',&quot;Memory&quot;)">
      <set token="Memory">True</set>
      <unset token="CPU" />
      <unset token="Disk" />
      <set token="CPU_Memory">True</set>
    </condition>
    <condition match="match('value',&quot;Disk&quot;)">
      <set token="Disk">True</set>
      <unset token="CPU" />
      <unset token="Memory" />
      <unset token="CPU_Memory" />
    </condition>
    </change>
</input>

Use depends=$CPU$ for only CPU related panels.
Use depends=$Memory$ for only Memory related panels.
Use depends=$CPU_Memory$ for both CPU & Memory panels.

Thanks

Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Path Finder

Hi,

Thanks for your answer.

However (maybe it's just me not completely understanding here), I have:

2 panels with CPU,
1panel with Memory

And that's it in my current configuration.

The point is to only show CPU OR Memory OR everything at the same time.

With your solution If I'm not wrong I should have another panel with both CPU and Memory?
So it would show only cpu or memory or the special panel with CPU and Memory.

My point is to only have 2 different kind of panels (CPU, Memory) and to display either of them or all of them.

Not sure if I'm clear about this here. But

0 Karma
Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Path Finder

Hi,

Thanks for your answer.

However (unless I'm completely wrong and I can not grasp the logic here), It would not do what I'm intending to do here:

I've got one panel with CPU, one with Memory and I want to either display one or the other one or both at the same time.

Based on your answer, I think I would not be able to have either of them separately or both at the same time.

Let's say:

CPU panel:
depends=$CPU$

Memory panel:
depends=$Memory$

Then.. what about this $CPU_Memory$ token? because I would need to create another panel with CPU and Memory inside and set the token on it.

Memory and CPU panel:
depends=$CPU_Memory$

But it wouldn't really use the two other panels above, only the 3rd one?

Am I wrong?

0 Karma
Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Path Finder

Hi,

You were right to use the set/unset command, I guess I wasn't completely clear on my question.

I solved the problem with the answer below from @rjthibod

Thanks for your help

0 Karma
Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Champion

Why can't you do this.

 <input searchWhenChanged="true" token="perf_choice" type="radio">
   <label>Panel Selector</label>
   <choice value="CPU">CPU</choice>
   <choice value="Memory">Memory</choice>
   <choice value="CpuMem">CPU &amp; Memory</choice>
   <change>
     <condition value="CPU">
       <set token="CPU">True</set>
       <unset token="Memory" />
     </condition>
     <condition value="Memory">
       <set token="Memory">True</set>
       <unset token="CPU" />
     </condition>
     <condition value="CpuMem">
       <set token="CPU">True</set>
       <set token="Memory">True</set>
     </condition>
     </change>
 </input>

And then still do what you said

CPU panel:
depends="$CPU$"

Memory panel:
depends="$Memory$"

View solution in original post

Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Path Finder

Hi,

I couldn't do this because I tortured my mind too much in the first place.
Your solution works perfectly thank you. Easy and efficient 🙂

Thanks again.

0 Karma
Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Champion

Thx, happy to help. No worries about torturing yourself, tokens can be a bit obtuse.

Shameless plug, check out my .conf talk on Tokens: http://conf.splunk.com/files/2017/slides/tokens-in-splunk-web-framework-use-abuse-and-incantations.p...

0 Karma
Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Legend

@llacoste, as you have already seen default behavior of depends attribute is to perform AND while using multiple tokens. You can refer to an answer to similar question which uses Simple XML JS Extension to apply your own JavaScript to handle multiple token as OR instead of AND: https://answers.splunk.com/answers/566582/how-to-hide-html-in-panel-when-multiple-tokens-are.html




| eval message="Happy Splunking!!!"


Highlighted

Re: [Solved] Displaying a panel depending on a token OR another

Path Finder

Hi,

Thanks for the link I'll have a look at it. I managed to do what I wanted with the answer from @rjthibod but I'll definitely keep your solution in mind for other use cases.

Cheers

0 Karma