Splunk Search

how to create splunk custom search command with java ?

Explorer

hi

I am trying to create a new custom search command with java, but I only found stuff related to python. Is it possible to create a custom search command with java?

0 Karma

Contributor

Does anyone know if this is possible. Based on the documentation, I don't think it's possible to create a custom search command in Java. It would have to be done with python

custom command documentation for python: 

https://dev.splunk.com/enterprise/docs/devtools/customsearchcommands/customsearchcmdexamples/

I went through the docs for Java and there's nothing in regards to custom commands

https://dev.splunk.com/enterprise/docs/devtools/java/plugin-eclipse/howtouseeclipse

 

splunk employees, can you help confirm? 

0 Karma

Super Champion

You need to use Splunk Java SDK. Very good documentation at: Splunk Java SDK documentation

The core logic being..

// Create the job
JobArgs jobArgs = new JobArgs();
jobArgs.setEarliestTime("rt-1m");
String mySearch = "search index=_internal";
Job job = service.search(mySearch, jobArgs);
// View the results--a stream of previews--using standard Java classes
JobResultsPreviewArgs previewArgs = new JobResultsPreviewArgs();

    InputStream stream = job.getResultsPreview(previewArgs);
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }
0 Karma

Explorer

hi koshyk
Thnx. i tried that one too but my requirement is i need to process those results and post back to splunk preview and this search has to work dynamically that means the input has to come from splunk search bar. this entire work has to be done with java

0 Karma

Super Champion

don't think i quite understood. Is this what you are trying to do ?
- run search1 & get results of search1
- create search2 with results of search1

(you said, you got examples in python. if you put that, i might look to convert to java)

0 Karma

Explorer

I need the following to be converted to java and run in splunk

Thanks InAdvance

http://docs.splunk.com/Documentation/Splunk/6.2.4/AdvancedDev/SearchScripts

0 Karma

Super Champion
0 Karma

Explorer

I need those in Java. Even though i convert code i don't have an idea whether it works or not

Contributor

any luck finding out if you can create custom search commands using Java?