|
|
This project provides a binary .dll, source code and examples for the .NET framework 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 .Net SDK
Splunk's .Net SDK is a public domain library providing .NET development wrappers 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 .Net 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:
- Authentication
- Search
- Configuration
We continue to work on implementing the wrappers for the other components of the server, including user roles and permissions.
Written entirely in C#, the SDK can be used with any language supported by .Net Framework 2.0
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 .Net SDK Library you will need the .Net framework installed:
- Microsoft .Net Framework 2.0 - Download .Net 2.0
To develop applications you will need one of the Software Development Kits (SDKs). Alternatively download one of the free Visual Studio Express editions. http://msdn.microsoft.com/vstudio/express/
Installation
Splunk .Net SDK is a dynamic linking library. You can download the latest version here.
Run the installer and follow the instructions to place the library file to the right folder.
Create a new Visual Studio 2005 project. In project's context menu, select "Add References", then under "Browse" tab select the splunknet.dll you've just downloaded.
Start your code with "using Splunk;" and you're all set to start writing code.
Documentation
The .dll contains embeded documentation for the different methods that can be called. Auto generated html documentation can be found here. More documentation will be added soon.
Example usage
// Initialize a connection object
SplunkConnection con = new SplunkConnection(server_name, port);
con.Authenticate(user, pass)
// Create new search manager
SearchManager searchManager = new SearchManager(con);
// Dispatch a new search job on Splunk server
SearchJob searchJob = searchManager.Dispatch("search error");
// Print all events in the dispatched job
foreach (SearchEvent searchEvent in searchJob)
{
Console.WriteLine("\nEvent #{0} contains {1} fields:", i++, searchEvent.CountFields());
foreach (DictionaryEntry entry in searchEvent)
{
Console.WriteLine(string.Format("{0}:{1}", entry.Key, entry.Value));
}
}
// Auto fill dataset
SplunkCommand cmd = new SplunkCommand("search sendmail", con);
SplunkDataAdapter sda = new SplunkDataAdapter(cmd.CommandText, con);
DataSet ds = new DataSet();
sda.Fill(ds);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.
- Retrieving search results and presenting them on a DataGrid.
- WebReport - sample web reporting/analytics dashboard application
- Dispatching and controlling search jobs.
- Working with configuration data.
Acknowledgements
SDK Documentation was generated using NDoc 2.0 Alpha, which can be found at http://www.kynosarges.de/NDoc.html
