Security

Substituting token names again

johnjester
Explorer

Simple question I hope.

I have a dashboard that uses many tokens from input drop downs, which allow the user to cause all dashboard elements to only consider events that match all the drop downs. In my dashboard elements I end up having to put long conditions, such as (made up example):

where ("$color$"="all" or "$color$"=color) and ("$type$"="all" or type="$type$") and ("$size$"="all" or size="$size$") and ....

In an effort to reduce how many times I need to copy/update this large list of conditions across all the dashboard elements, I was hoping I could define a token like this:

<init>
  <set token="cond">
    ("$color$"="all" or "$color$"=color) and ("$type$"="all" or type="$type$") and ("$size$"="all" or size="$size$") and ....
  </set>
</init>

That appeared to work by just putting a "where $cond$" in each element instead of the long condition, but now my dashboard elements didn't react to changes in the drop downs. So I tried using $$ instead for the "cond" definition, but this causes all elements to return no results. I figure this is probably because the inner tokens are not being substituted for their proper values. Is there a way to cause this second level of substitution to happen? Or, is there another way I can accomplish the same goal of defining my large condition in a single place?

Tags (1)
0 Karma
1 Solution

cmerriman
Super Champion

you can't use <set> when doing an eval like this. you'll need to do <eval>. you probably wouldn't want this under <init> because you don't initially know what all of those tokens are set as.
http://docs.splunk.com/Documentation/Splunk/7.0.2/Viz/tokens#Define_token_filtering_and_formatting
perhaps something like this:

<fieldset>
a bunch of inputs
<change>
<eval token="cond">("$color$"="all" or "$color$"=color) and ("$type$"="all" or type="$type$") and ("$size$"="all" or size="$size$") and .... </eval>
</change>

View solution in original post

0 Karma

cmerriman
Super Champion

you can't use <set> when doing an eval like this. you'll need to do <eval>. you probably wouldn't want this under <init> because you don't initially know what all of those tokens are set as.
http://docs.splunk.com/Documentation/Splunk/7.0.2/Viz/tokens#Define_token_filtering_and_formatting
perhaps something like this:

<fieldset>
a bunch of inputs
<change>
<eval token="cond">("$color$"="all" or "$color$"=color) and ("$type$"="all" or type="$type$") and ("$size$"="all" or size="$size$") and .... </eval>
</change>
0 Karma

johnjester
Explorer

Also, I don't believe I want to use the eval node, because that results in the whole expression being evaluated to true or false. I want the full evaluation to wait until the search time on each dashboard element, so that each dashboard element can evaluate the condition for each of the events it is considering.

0 Karma

johnjester
Explorer

I tried to add the change tag inside fieldset but got the warning

Node <change>  is not allowed here

Edit - I realized that I needed to put the change node in each input, and if I use set to change the token using single $, it all works.

Thanks for getting me on the right track!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...