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!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...