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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...

Updated Data Management and AWS GDI Inventory in Splunk Observability

We’re making some changes to Data Management and Infrastructure Inventory for AWS. The Data Management page, ...