Install the SDK

After you've taken care of the prerequisites, you're ready to install the components of the Splunk® SDK for JavaScript.

 

Get the SDK

Get the Splunk SDK for JavaScript: download the SDK as a ZIP file and extract the files.

Want to verify your download? Download MD5. Download SHA-512.

 

Client-side installation

The Splunk SDK for JavaScript includes pre-built client-side files that run in a web browser. To install the client-side files, you just need to copy them to your site and include them in your code. The client-side SDK also uses the jQuery library, so you also need jquery.min.js.

To install the client-side files

  1. Copy the /splunk-sdk-javascript/client directory to your site.
  2. Copy jquery.min.js, which is included with the SDK in /splunk-sdk-javascript/examples/browser/resources, to your site.
  3. Include one of the following <script> tags in your client-side code, specifying the correct path to the files on your site:
  4. <script type="text/javascript" src="/YOUR_PATH/splunk.js"></script>
    

    Or:

    <script type="text/javascript" src="/YOUR_PATH/splunk.min.js"></script>
    

    This tag creates a global variable called splunkjs, which is the root of the SDK. No other global variables are introduced.

  5. Include a <script> tag specifying the correct path to the jquery.min.js file:
  6. <script type="text/javascript" src="/YOUR_PATH/jquery.min.js"></script>
    
 

Server-side installation

The Splunk SDK for JavaScript requires Node.js for server-side scripting. To use the Splunk SDK for JavaScript in your own Node.js programs, install the server-side files and require them in your script.

To install the server-side files

  1. At the command line, go to your project's directory and enter:
  2. npm install splunk-sdk
  3. Use the require() function in your script as follows:
  4. var splunkjs = require('splunk-sdk');
 

xml2json, the XML to JSON Splunk app

The XML to JSON Splunk app (xml2json) converts XML output to JSON, and is required if:

  • You are using Splunk 4.2.x or 4.3.x.
  • You want to run the unit tests (with any Splunk version).

JavaScript uses the JavaScript Object Notation (JSON) format for structured data. The Splunk SDK for JavaScript provides a Splunk app, xml2json, that converts the XML that Splunk returns into JSON.

To install the xml2json app

  1. Copy the xml2json directory (/splunk-sdk-javascript/xml2json) to the Splunk apps directory ($SPLUNK_HOME/etc/apps), or create a symbolic link to the xml2json directory.
  2. The following examples show how to do this at the command line.

    On OS X or Linux: To copy the xml2json directory to the Splunk apps directory, go to the /splunk-sdk-javascript directory and enter:

    cp -r xml2json /applications/splunk/etc/apps/xml2json

    Or, to create a symbolic link to the xml2json directory, enter:

    ln -s /users/currentusername/splunk-sdk-javascript/xml2json 
    /applications/splunk/etc/apps/xml2json

    On Windows: To copy the xml2json directory to the Splunk apps directory, enter:

    xcopy C:\splunk-sdk-javascript\xml2json "C:\Program Files\Splunk\etc\apps
    \xml2json" /s
  3. Restart Splunk.
  4. On OS X or Linux: Go to the /Applications/splunk/bin directory and enter:

    ./splunk restart

    On Windows: Go to the C:\Program Files\Splunk\bin directory and enter:

    splunk restart
 

Use the Splunk SDK for JavaScript components on your web page

To use the components from the Splunk SDK for JavaScript on your web page, copy the /splunk-sdk-javascript/client directory to your web server. Then, include the splunk.js or splunk.min.js file from this directory in your code.

For example, include one of the following tags in your code:

<script type="text/javascript" src="/yourpath/splunk.js"></script>

Or:

<script type="text/javascript" src="/yourpath/splunk.min.js"></script>

You can also include the UI components, such as the Timeline and Charting controls. These UI component files (splunk.ui.timeline and splunk.ui.charting) are also in the /splunk-sdk-javascript/client directory.

 

Install the Splunk SDK for JavaScript for Node.js apps

Note: The Splunk SDK for JavaScript v1.2.3 and later requires Node.js version 0.8.x or 0.10.x.

If you want to use the Splunk SDK for JavaScript with your Node.js programs, install the SDK by running npm in your project's directory as follows:

npm install splunk-sdk

Then, to include the Splunk SDK for JavaScript, use the require function in your code:

var splunkjs = require('splunk-sdk');