Dashboards & Visualizations

How to extract value from token in init section

kotak86
Explorer

Hello I am trying to get substr in init but it looks like it's not working.

the problem is $data_type$ value is "(data_type=state)" or "(data_type=country)" or "(data_type=state OR country)"

I need a way to create another token like cur_data which can get the substr of $data_type$ from idx 8 -12

I tried but substr in inti did not work...
<eval token="cur_data">substr($data_type$, 8,12)</eval>
data_type field is part of fieldset and taking from user from dashboard filter

 

 

 

<init>
<set token="STATE_DATA">STATE_1, STATE_2, STATE_3, STATE_4</set>
<set token="COUNTRY_DATA">COUNTRY_1, COUNTRY_2, COUNTRY_3, COUNTRY_4 </set>
<eval token="cur_data">substr($data_type$, 8,12)</eval>
<eval token="VCS_TYPES">if($cur_data$='state', $STATE_DATA$,  $COUNTRY_DATA$)</eval>

</init>

 

 

Labels (4)
Tags (1)
0 Karma
1 Solution

niketn
Legend

@kotak86 since you are trying to use a token in the init section, which does not seem to be set during dashboard initialization, your dependent token is not getting set. Try to use an independent search instead, which also runs on Dashboard load as well as each time source token changes,

  <search>
    <query>| makeresults
    | fields - _time
    | eval cur_data=substr($data_type|s$, 8,12)</query>
    <done>
      <set token="cur_data">$result.cur_data$</set>
    </done>
  </search>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@kotak86 since you are trying to use a token in the init section, which does not seem to be set during dashboard initialization, your dependent token is not getting set. Try to use an independent search instead, which also runs on Dashboard load as well as each time source token changes,

  <search>
    <query>| makeresults
    | fields - _time
    | eval cur_data=substr($data_type|s$, 8,12)</query>
    <done>
      <set token="cur_data">$result.cur_data$</set>
    </done>
  </search>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...