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
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...