Dashboards & Visualizations

Handling splunk dashboard token

kranthimutyala
Path Finder

Hi All,

I have a dashboard which contains 2 inputs(both are text fields ).But the user can give the values in both the text fields or he can give only in one of the text fields leaving the other one blank(but the query in the panel doesn't work if any of the token is null)

So when he gives the input in first field the second should be * and vice versa.
But i do want to show the * in the text box by setting up it in the default value

Or how can i ignore the second token(assuming nothing is provided) in the panel search query so that it can generate the results based on one token

Sample query in the panel : index=abc event=$token1$ agent=$token2$ | table action object

Can someone help me on how to handle this situation.

Thank you in advance

0 Karma
1 Solution

gaurav_maniar
Builder

Hi,

below code will resolve your issue,

<input type="text" token="tok2">
    <label>field2</label>
    <default>*</default>
</input>

Accept and upvote the answer if it helps.

happy splunking........!!!!

View solution in original post

gaurav_maniar
Builder

Hi,

below code will resolve your issue,

<input type="text" token="tok2">
    <label>field2</label>
    <default>*</default>
</input>

Accept and upvote the answer if it helps.

happy splunking........!!!!

kranthimutyala
Path Finder

This will show (*) as default values but i want to hide it in the back bot showing up to the user

0 Karma

Anantha123
Communicator

Hi , Try below . Give space in default.

  <label>field1</label>
  <default></default>
</input>
0 Karma

kranthimutyala
Path Finder

thats not working

0 Karma

kranthimutyala
Path Finder

Please find the below code.In the below code whenever user doesn't specify any value for either source/log_level it must be replaced with *.
But i don't want to use * in default value as user doesn't want to see that.So need your help in handling this token whenever it is null change it to * internally using eval.Thank you

input_test

<input type="text" token="src">
  <label>specify source</label>
</input>
<input type="text" token="log">
  <label>log_level</label>
</input>
<input type="time" token="field1">
  <label></label>
  <default>
    <earliest>-24h@h</earliest>
    <latest>now</latest>
  </default>
</input>


<panel>
  <table>
    <search>
      <query>index=_internal sourcetype=$src$ log_level=$log$|table sourcetype log_level</query>
      <earliest>-24h@h</earliest>
      <latest>now</latest>
    </search>
    <option name="count">10</option>
    <option name="drilldown">none</option>
    <option name="refresh.display">progressbar</option>
  </table>
</panel>
0 Karma

gaurav_maniar
Builder

Hi,

If your are fine with using javascript, below code will work,

<form script="default_token.js">
  <label>Default Token</label>
  <fieldset submitButton="true">
    <input type="text" token="token1">
      <label>Field</label>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Default Token</title>
      <table>
        <search>
          <query>index=_internal sourcetype=$token1$ | head 1 | table _time, _raw</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
      </table>
    </panel>
  </row>
</form>

default_token.js
require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/searchmanager',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView, SearchManager) {

    var tokens = mvc.Components.get("default");

    $(document).on("click", "#submit", function(e){
        var tok1 = tokens.get("token1");

        if (tok1 == undefined || tok1 == ""){
            tokens.set("token1", "*");
        }
    });
});
0 Karma

kranthimutyala
Path Finder

$(document).on("click", "#submit", function(e){
var tok2 = tokens.get("token2");

     if (tok2 == undefined || tok2 == ""){
         tokens.set("token2", "*");

I have added this snippet for token2, but its not working .Can you please help me with the script for more than one token change

0 Karma

kranthimutyala
Path Finder

@gaurav_maniar Thanks for your answer, its working well.Thank you very much

0 Karma

kranthimutyala
Path Finder

require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/searchmanager',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView, SearchManager) {

 var tokens = mvc.Components.get("default");

 $(document).on("click", "#submit", function(e){
     var tok1 = tokens.get("token1");

     if (tok1 == undefined || tok1 == ""){
         tokens.set("token1", "*");
     }
 });

 $(document).on("click", "#submit", function(e){
     var tok2 = tokens.get("token1");

     if (tok2 == undefined || tok2 == ""){
         tokens.set("token2", "*");
     }
 });

});

this code is not working , i want to implement this for two tokens

0 Karma

tomawest
Path Finder

Set the default value for both text fields to *.
Your issue is that the token is unset when nothing is entered in.

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 ...