Dashboards & Visualizations

Loading an external JS file in splunk

nadlurinadluri
Communicator

I need to load a js from external location (google maps js which Google exposes), instead of storing it in /appserver/static location. Is it possible to do that?

0 Karma

niketn
Legend

@nadlurinadluri please check out Splunk Custom Visualization API documentation if you need to use external JS for visualization: https://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/CustomVizTutorial#Create_the_visuali...

One other option would be to convert to HTML dashboard (however, you will lose Simple XML dashboard and several other features and editing dashboard would not be easy unless you are familiar with HTML, JS, CSS and Splunk Web Framework): http://dev.splunk.com/view/SP-CAAAEN6

If this is for GoogleMapView, you can try out Splunk Web Framework with Simple XML JS Extension using SplunkJS view: https://docs.splunk.com/DocumentationStatic/WebFramework/1.1/compref_googlemap.html

If it is plain js file (unlike with async defer options with Google Maps JS), you can also use simple XML JS Extension to directly include the CDN url. For example js with d3 CDN (d3_cdn.js) below which can be used in Dashboard:

require(["jquery", 
         "https://d3js.org/d3.v5.min.js",
         "splunkjs/mvc/simplexml/ready!"], function($, d3) {
    console.log("D3 Script Loaded");
    d3.selectAll("#mydiv p").style("color", "blue");
});

Following is a run anywhere example:

<dashboard script="d3_cdn.js">
  <label>D3 Using CDN</label>
  <row>
    <panel>
      <html>
        <div id="mydiv">
          <p>Some Text here.</p>
          <p>Some Text there.</p>
        </div>
      </html>
    </panel>
  </row>
</dashboard>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...