Dashboards & Visualizations

How to use JavaScript code in Splunk Cloud dashboard ?


I would like to fetch query string value through script in splunk cloud dashboard or in report so how it can be possible ?

For ex. www.splunkcloud.com ? q=TRY

Dashboard source code of cloud

alt text
I am not able to call any script. its giving error.

If i want to use q's value TRY in any search query like report,chart,dashboard then how it is possible?

Thanks in advance.


@shukan, While you can use <style> tag directly in Splunk Simple XML dashboards to load/override CSS style, Javascript does not work this way. You will need to use Simple XML JS Extension.

There are several examples on Splunk Dashboard Examples app on Splunkbase ( https://splunkbase.splunk.com/app/1603/ )
You can also refer to Splunk Dev site for the same: http://dev.splunk.com/view/SP-CAAAE4A#editjs

Following is an example of dashboard which uses hello_world.jsJavaScript file.

alt text

<dashboard script="hello_world.js">
  <label>Hello World JavaScript Example</label>
          Splunk Simple XML JavaScript Extension to show Hello World alert and console log using JavaScript file <b>hello_world.js</b>.
          The JavaScrpt File needs to be placed under the Splunk App's Static folder i.e. <b>$SPLUNK_HOME$/apps/etc/$env:app$/appserver/static</b>, based on the current app <b>$env:app$</b>.
          Following is the JavaScript Code:<br/><br/> 
            ], function() {
              alert("Hello World");
                console.log("Console Log: Hello World");
          PS: Press <code>F12</code> to Open Browser Inspect Tool to view JavaScript console log. 

Following is the code for JavaScript file which needs to be placed under your Splunk app's static folder:

        ], function() {
            alert("Hello World");
            console.log("Console Log: Hello World");

PS: If you want to load Static files like Javascript file on Splunk Cloud you should test the same on your local Splunk Instance and then reach out to Splunk Support for getting the same uploaded to your Splunk Cloud instance.

| makeresults | eval message= "Happy Splunking!!!"


Is there a way to add the java script in xml inline?

I am using cloud version and don't have rights to add the script in path.

Path Finder

I'm looking for this as well, for colocation reasons. But so far I haven't found a way.

For people playing along at home: web.conf has a few options for dashboards (like dashboard_html_allow_embeddable_content), but seemingly nothing to allow embedding scripts.

0 Karma
Get Updates on the Splunk Community!

New Release | Splunk Enterprise 9.3

Admins and Analyst can benefit from:  Seamlessly route data to your local file system to save on storage ...

2024 Splunk Career Impact Survey | Earn a $20 gift card for participating!

Hear ye, hear ye! The time has come again for Splunk's annual Career Impact Survey!  We need your help by ...

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...