Splunk Search

how to create splunk custom search command with java ?

kalyani_y
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

spammenot66
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

koshyk
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);
    }

kalyani_y
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

koshyk
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

kalyani_y
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

koshyk
Super Champion
0 Karma

kalyani_y
Explorer

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

jagadeeshm
Contributor

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

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...