Skip to content

Instantly share code, notes, and snippets.

Damien Dallimore damiendallimore

Block or report user

Report or block damiendallimore

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View CreateUserExample.java
/**
* Create a user and then update it
*/
private static void createUserExample() {
Service splunkService = connectAndLoginToSplunkExample();
String username = "testuser";
String password = "changeme";
String[] roles = { "power", "testrole" };
User user = splunkService.getUsers().create(username, password, roles);
View CreateRoleExample.java
/**
* Create a role and then update it
*/
private static void createRoleExample() {
Service splunkService = connectAndLoginToSplunkExample();
// Create a new role called 'testrole'
Role role = splunkService.getRoles().create("testrole");
View UploadFileExample.java
/**
* Perform a oneshot file upload
*/
private static void uploadFileExample() {
Service splunkService = connectAndLoginToSplunkExample();
// Retrieve the index for the data
Index myIndex = splunkService.getIndexes().get("main");
View UdpInputDataExample.java
/**
* Send some data to Splunk over UDP
*/
private static void udpInputDataExample() {
Service splunkService = connectAndLoginToSplunkExample();
// Get a UDP input to send to
UdpInput myInput = (UdpInput) splunkService.getInputs().get("9999");
View NamespaceGetEntityExample.java
/**
* Get a list of objects(saved searches) in a namespace
*/
private static void namespaceGetEntityExample() {
Service splunkService = connectAndLoginToSplunkExample();
ServiceArgs namespace = new ServiceArgs();
namespace.setOwner("admin");
namespace.setApp("search");
SavedSearchCollection savedSearches = splunkService.getSavedSearches(namespace);
View SavedSearchWithRuntimeArgsExample.java
/**
* Saved Search with dynamic search arguments example
*/
public static void savedSearchWithRuntimeArgsExample() {
Service splunkService = connectAndLoginToSplunkExample();
String myQuery = "search index=_internal sourcetype=$args.mysourcetype$ | head 5";
String mySearchName = "My Test Search";
//create the saved search
View ProcessInputStream.java
/**
* Print out the results using an appropriate ResultsReader for the passed
* output mode.
*
* Using incremental streaming , data is parsed and returned in key-value
* pairs
*
* The JSON and CSV results readers requires an external jar (gson-2.1.jar,
* opencsv-2.3.jar) for json and csv parsing and is not part of the base
* Splunk Java SDK. These readers are found in the "com.splunk.external"
View NamespaceCreateEntityExample.java
/**
* Create an object(a saved search) in a namespace
*/
private static void namespaceCreateEntityExample() {
Service splunkService = connectAndLoginToSplunkExample();
ServiceArgs namespace = new ServiceArgs();
namespace.setOwner("admin");
namespace.setApp("search");
SavedSearchCollection savedSearches = splunkService.getSavedSearches(namespace);
View AsyncSearchJobExample.java
/**
* Submit a search job exec_mode = normal , asynchronous
*/
public static void asyncSearchJobExample() {
Service splunkService = connectAndLoginToSplunkExample();
OutputMode outputMode = OutputMode.JSON;// xml,json,csv
JobArgs queryArgs = new JobArgs();
View RealTimeSearchExample.java
/**
* Submit a realtime search job exec_mode = normal , asynchronous
*/
public static void realTimeSearchExample() {
Service splunkService = connectAndLoginToSplunkExample();
JobArgs queryArgs = new JobArgs();
//5 minute sliding realtime window
You can’t perform that action at this time.