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 am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

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