Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Saved Search Example
*/
public static void savedSearchExample() {
Service splunkService = connectAndLoginToSplunkExample();
String myQuery = "search index=_internal * | head 5";
String mySearchName = "My Test Search";
//create a new saved search
SavedSearch savedSearch = splunkService.getSavedSearches().create(mySearchName, myQuery);
try {
//dispatch the search job
Job jobSavedSearch = savedSearch.dispatch();
while (!jobSavedSearch.isDone()) {
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
processInputStream(jobSavedSearch.getResults(), OutputMode.XML);
} catch (Exception e) {
}
//remove the saved search
splunkService.getSavedSearches().remove(mySearchName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.