Dashboards & Visualizations

How to prevent tokens that use other tokens from losing their values

greggz
Communicator

From the title this might sound confusing but what I'm getting at is:

$token1$ = "something"

$token2$ = search index=$token1$

After refreshing the browser, token1 retains it's value but token2 loses the index="something" part and changes to index=$token1$

Is there any way of working around this issue ?

SimpleXML

I have a checkbox that juggles around with two tokens. $p2$ is the one giving problems, because when I select him he becomes like this:

1 - | appendcols [search index=esi_configmock host=* sourcetype=cnf source=server.cnf earliest=-6mon | table watt* host | transpose column_name=Property header_field=host 50]

And if I decide to refresh the page, he reverts to

2 - | appendcols [search index=configmock host=$server$ sourcetype=$file_type$ source=$file_name$ earliest=-6mon | table $prefixes$ host | transpose column_name=Property header_field=host 50]

And this is the problem! I can't have this behaviour happen, I need the token to remain with the value at 1.

  <input type="checkbox" token="SingleMode" searchWhenChanged="true">
    <label>Single Mode</label>
    <choice value="single"> Single Mode Host </choice>
    <change>
       <condition value="single">
         <set token="p1"> eval time = strftime(_time,"%c") | eval host = host." at ".time | sort by time| </set>
         <set token="p2"></set>
       </condition>
       <condition>
         <set token="p1"></set>
         <set token="p2"> | appendcols  [search index=configmock host=$server$ sourcetype=$file_type$ source=$file_name$ earliest=-6mon | table $prefixes$ host | transpose column_name=Property header_field=host 50] </set>
     </condition>
     </change>
    </input>
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @greggz,

The reason you are not achieving your requirement is token p1 & p2 is set on onchange event of checkbox. So when you are refreshing p2 will not set. I have tried to make it possible by using javascript. Can you please try my sample code?

XML

<form script="my.js">
  <label>Test panel showing</label>
  <description>Grrr why doesnt this work?</description>
  <fieldset submitButton="false">

    <input type="text" token="server">
      <label>server</label>
    </input>
    <input type="text" token="file_type">
      <label>file_type</label>
    </input>
    <input type="text" token="file_name">
      <label>file_name</label>
    </input>
    <input type="text" token="prefixes">
      <label>prefixes</label>
    </input>
    <input type="checkbox" token="SingleMode" id="idSingleMode" searchWhenChanged="true">
      <label>Single Mode</label>
      <choice value="single">Single Mode Host</choice>
    </input>
  </fieldset>
  <row>
    <panel>
      <html>p1= $p1$<br/>p2=$p2$ <br/></br>
      </html>
    </panel>
  </row>
</form>

my.js

require([
     'underscore',
     'jquery',
     'splunkjs/mvc',
     'splunkjs/mvc/simplexml/ready!'
 ], function(_, $, mvc) {
     // Access the "default" token model
     var defaultTokenModel = mvc.Components.get('default', {create: true});
     var submittedTokens = mvc.Components.get('submitted');


    var idSingleMode = mvc.Components.get('idSingleMode');

    idSingleMode.on('change', function(value) 
    {
      setToken(value);
    });

    submittedTokens.set(defaultTokenModel.toJSON());
    console.log(idSingleMode);
    var SingleMode = defaultTokenModel.get("SingleMode");
    console.log(SingleMode);
    if(SingleMode===undefined) {
      setToken([]);
    }
    else {
      setToken([SingleMode]);
    }
    function setToken(value)
    {
      console.log("idSingleMode",value);
      if(value.length==1)
      {
        defaultTokenModel.set("p1", "eval time = strftime(_time,\"%c\") | eval host = host.\" at \".time | sort by time|"); 
        defaultTokenModel.set("p2", ""); 
      }
      else {
        defaultTokenModel.set("p1", ""); 
        defaultTokenModel.set("p2", "| appendcols [search index=configmock host="+defaultTokenModel.get("server")+" sourcetype="+defaultTokenModel.get("file_type")+" source="+defaultTokenModel.get("file_name")+" earliest=-6mon | table "+defaultTokenModel.get("prefixes")+" host | transpose column_name=Property header_field=host 50]"); 
      }

      submittedTokens.set(defaultTokenModel.toJSON());
    }
 });

Thanks

greggz
Communicator

@kamlesh_vaghela Thanks for your answer, but I know I can do it with Js. Maybe I should have specified that I was looking for a solution in the SimpleXML realm 🙂

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @greggz,

Can you please share your sample xml?

0 Karma

greggz
Communicator

@Kamlest_vaghela I'm not really allowed to share the simpleXml. I could create a mockup example if necessary.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @greggz,
Make sense. the mockup is good for to go ahead.

Thanks

0 Karma

greggz
Communicator

@kamlesh_vaghela I updated the question, pls do a recheck thanks

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

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