Dashboards & Visualizations

set simple xml token from java script file

ssujin
Explorer

How to set a panel's depends tag value from java script with simple XML?

  <row>
    <panel>
      <chart depends="$check_status$">
        <title>Check Status</title>
        <searchString>......</searchString>
        <option name="charting.chart">line</option>
        <option name="charting.chart.nullValueMode">connect</option>
        <option name="charting.axisTitleX.text">Time</option>
        <option name="charting.axisTitleY.text">check status</option>
        <option name="charting.axisY.scale">linear</option>
        <option name="charting.axisY.minimumNumber">-1</option>
        <option name="charting.axisY.maximumNumber">3</option>
        <option name="charting.axisLabelsY.majorUnit">1</option>
        <!--<option name="link.visible">false</option>-->
      </chart>
    </panel>
  </row>

in the above example value for check_status has to set from java script.
Kindly provide example java script code.

0 Karma
1 Solution

kbarker302
Communicator

Below is a sample of JavaScript I use to set a token:

require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function(mvc) {

    var tokens = mvc.Components.get("default");
    tokens.set("check_status", "true");              
});

Presumably your JavaScript would have some code to check whether or not to set the token. Also, depending on your logic, you may want to unset the token as well like this:

tokens.unset("check_status");    

Not sure how familiar you are with using JavaScript in Splunk, but your JavaScript file would go here (create the folders if they don't already exist):

$SPLUNK_HOME\etc\apps\<yourapp>\appserver\static

and you would reference it in your XML like this, by adding a script attribute to your form or dashboard tag:

<form script="yourjavascript.js">

View solution in original post

kbarker302
Communicator

Below is a sample of JavaScript I use to set a token:

require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function(mvc) {

    var tokens = mvc.Components.get("default");
    tokens.set("check_status", "true");              
});

Presumably your JavaScript would have some code to check whether or not to set the token. Also, depending on your logic, you may want to unset the token as well like this:

tokens.unset("check_status");    

Not sure how familiar you are with using JavaScript in Splunk, but your JavaScript file would go here (create the folders if they don't already exist):

$SPLUNK_HOME\etc\apps\<yourapp>\appserver\static

and you would reference it in your XML like this, by adding a script attribute to your form or dashboard tag:

<form script="yourjavascript.js">

ssujin
Explorer

Is it possible to read the data from text file using javascript? Because while i was trying i got error.

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...