My favorites | Sign in
Project Logo
                
Code license: New BSD License
Show all Featured downloads:
SplunkJava.1.1_sdk5.jar
Feeds:
Groups:

This project provides a library with source code and examples written in Java for coding against the Splunk Platform APIs.

More information on coding against Splunk is hosted over on the Splunk Labs pages at: http://code.google.com/p/splunk-labs/

Splunk Java SDK

Splunk's Java SDK is a public domain library providing Java development wrapper for projects based around Splunk's search engine.

Please note this an early beta release of the SDK, and as such, hasn't been throughly tested. If you find any bugs, or need assistance feel free to leave a comment on the Splunk Labs list, opening a ticket, or check out the code yourself and get busy! Note: Don't email Splunk directly about support for this library - your requests will go unanswered if you do.

You can request to join the Splunk Labs project here on Google Code by emailing your Gmail email address in the SUBJECT line of your email to splunk-labs@splunk.com.

Introduction

Splunk Java SDK is a wrapper around Splunk's REST API, providing an object model for the major functional components of the Splunk server. The following components are currently accessible via the SDK:

We continue to work on implementing the wrappers for the other components of the server, including user roles and permissions.

There are many levels of possible Splunk integration, so we provided developers the ability to communicate with the Platform API - from raw http streaming to custom-tailored objects and SQL-style components.

Requirements

To run the Splunk Java SDK Library you will need the Java runtime library installed:

Installation

Splunk Java SDK is a jar library. You can download the latest version here.

Launch your favorite Java development IDE. Create a new project. Import Splunk SDK library to the list of project's referenced libraries.

Documentation

The archive contains embeded documentation for the different methods that can be called. Javadoc for the project can be found here. More documentation will be added soon.

Example usage

This simple example establishes a connection with a Splunk server, using it to dispatch a new search job. Then it receives search results and sends them to standard output.

// Initialize a connection object
String user = "admin";
String password = "changeme";
String hostUrl = "https://localhost:8089";
String query = "search error";

SplunkConnection sc = new SplunkConnection(hostUrl);
sc.Authenticate(user, password);

// Create new search manager
SearchManager searchMgr = new SearchManager(sc);

// Dispatch a new search job on Splunk server
SearchJob job = searchMgr.Dispatch(query);
    		
// Print all events in the dispatched job
List<SearchEvent> events = job.GetEvents(null);
for(SearchEvent event : events)
{
    System.out.print("\n\n" + event.getTime() + " " + event.getRawData());
}
   		
// Release resources	
job.Cancel();

Test it by running it from jar file:

java -cp SplunkJava.1.0.jar Test <serverPath> <userName> <password> <searchQuery>

Examples

If you host a Splunk install on your own server you don't need to obtain a public API key. A session key will be assigned to your program automatically based on your login and password.

  1. Dispatching and controlling search jobs.
  2. How to list active search jobs.

Acknowledgements

JDOM 1.1 open source library was used in this project. JDOM is available under an Apache-style open source license download.









Hosted by Google Code