Splunk Search

Is there an option to stop a search job after a certain time through Splunk REST API?

senthilkumar76
Engager

I have a Splunk search which takes long time to execute. I want to stop the Splunk job if it doesn't complete in a minute or 2. Does Splunk REST API have an option for that?

I tried autocancel, timeout and job.cancel, nothing works. Any help greatly appreciated.

code snippet

    JobArgs jobargs = new JobArgs();
    jobargs.setAutoCancel(60);
    jobargs.setTimeout(0);
    jobargs.setExecutionMode(JobArgs.ExecutionMode.BLOCKING);

Service service =splunkconnection.connect();            
Job job = service.getJobs().create(query, jobargs);

JobResultsArgs resultsArgs = new JobResultsArgs();
resultsArgs.setCount(0);
resultsArgs.setOutputMode(JobResultsArgs.OutputMode.JSON);
InputStream resultsNormalSearch = job.getResults(resultsArgs);

reader= new ResultsReaderJson(resultsNormalSearch);
HashMap<String, String> event;
while ((event = reader.getNextEvent()) != null) {
  -- process response
}
resultsReader.close();
job.cancel();
0 Karma

Jeremiah
Motivator

It looks like you can send a cancel request via the job control API:

http://docs.splunk.com/Documentation/Splunk/6.4.3/RESTREF/RESTsearch#search.2Fjobs.2F.7Bsearch_id.7D...

It doesn't look exactly like what you are looking for, but there is also an auto_cancel and auto_finalize option to the jobs method when you submit a job.

http://docs.splunk.com/Documentation/Splunk/6.4.3/RESTREF/RESTsearch#POST_search.2Fjobs_method_detai...

senthilkumar76
Engager

we can't get the jobid to send a cancel request. but the auto cancel seems to be working. Thanks.

0 Karma

senthilkumar76
Engager

Does any know how to implement this?

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...