The Splunk JavaScript SDK allows you to easily build complex applications and visualizations using splunkjs. This page is your launchpad to the browser-side examples included in the SDK.
We believe examples are one of the key ways to increase understanding and expertise of our SDKs. This page provides
a gateway to all the browser-side examples (the server-wide ones can be launched from the console at
examples/node
). The examples will take you from the beginning (listing apps and creating searches) to
more complicated use cases such as integrating with 3rd-party visualization tools, and finally to MiniSplunk, a
clone of the some of the core Splunk features using the SDK.
There are a couple of notes that apply to most of the examples:
All the examples (with the exception of MiniSplunk) provide you with a code snippet (or several), and the ability to run that code. It will execute against your own install of Splunk, as specified by you at the top of that page. Please do run the examples!
As noted in our documentation, the SDK needs to communicate with Splunkd, which does not leave on the same host
as the web server that is serving your page. Due to the browser's Single Origin Policy, we can't talk to it directly.
The method that we use for the examples is to provide all the parameters to the example webserver, which will
then proxy it to Splunkd. This is what those ProxyHttp
lines are all about.
However, another option is to use the bundled XdmHttp
client (using easyXDM). The examples don't use it
as it can run into issues with unsigned SSL certificates due to browser security policies. Don't worry though - the
change from using ProxyHttp
to XdmHttp
is less than 2 lines!
We highly recommend you open up the developer console while the examples are running to see what requests the SDK is making. It can be quite educational.
These examples are meant to show off single, simple aspects of the SDK. They have nearly no configuration, and are mirror images of the respective server-side examples. Here, you'll see how to list all applications, list saved searches and their queries, and create various types of searches and get their results (even for real-time searches!).
Every one of the above examples is runnable in your browser, and you'll see the output in a dedicated output pane. Note that some examples have several versions - for example, the application listing example shows you the same code with and without the `splunkjs.Async` library.
Splunk has always had very strong visualization capabilities, both for giving you an overview of your event timeline, as well as being able to chart your queries in meaningful ways. We're excited to be able to give you access to the Splunk Timeline control and the Splunk charting control. These are the same controls that ship with Splunk 4.3 (no flash!). We didn't exclude or limit them in any way, and we hope that you find them useful to better visualize your data.
These examples show how to use both the Timeline and Charting control with the SDK. They will execute a simple search on Splunk, and visualize the data as it is available.
Note: while the controls work bestwith the SDK (as it provides data in the formats they expect), the
SDK itself is not required. There is a minimal module (splunk.ui.{min}.js
) that contains just the
asynchronous script loader to bring up the UI controls you desire.
As noted above, Splunk has extremely strong visualization tools. However, we simply can't think (or even implement) every type of visualization out there. Now, with the JavaScript SDK, visualizing your Splunk data in new and exciting ways has never been easier.
These examples show how to integrate Splunk search results with two 3rd-party visualization libraries:
Google Charts - a simple, yet powerful charting library provided by Google.
Rickshaw - a newly released time series visualization library. Based on the extremely powerful d3 library.
Note: the Rickshaw example will not work in <= IE9 due to browser limitations.
As you can imagine, the Splunk Web UI (Splunkweb) is the most complex Splunk application in the world, and also the largest user of the REST API. Given that premise, it was important to show that the JavaScript SDK can build a similar application - and so MiniSplunk was born.
MiniSplunk was the first example we wrote, and also the most complex one. It shows how to build a full application using the SDK - you can search, manage jobs, and even see your search results mapped (if they have geodata in them). We will keep updating the example to also include timeline and charting capabilities, as well as other advanced features as time progresses.