Splunk Dev

SplunkSDK SplunkJS oneshotSearch unable to get splunk query result as response

AnandSurya
New Member

Hi Team,

I am using SplunkSDK version 1.12.1 (splunk-sdk@1.12.1). We are using oneshotSearch to get splunk query data from the Get api. Please see below code snippet for executeSearch

 

 

module.exports.executeSearch = function (query, params, cb) {        
        splunkService.oneshotSearch(query, params, function (err, results) {
        console.log("Query is : "+query);
        cb(err, results);
  });
};

 

 

Below code is from where we are calling above 

 

 

SplunkQuery.executeSearch(splunkSearch, splunkParams, function (err, results) {  
   if (err) {
      if (err.data && err.data.messages) {
        Log.error(err.data.messages);
      }
      var error = Boom.badRequest();
      error.reformat();
      error.output.payload = Response.buildResponse(Errors.ERROR_RECORD_RETRIEVAL_FAILURE, []);
      // return reply(error);
      throw err;
    }
    var events = [];
    var rawRowIndex = results.fields.indexOf('_raw');
    if (results.rows.length == 0 && request.query.id) {
      var error = Boom.badRequest();
      error.reformat();
      error.output.payload = Response.buildResponse(Errors.ERROR_INVALID_ID_PARAM, []);
      return h.response(error);
    }

    for (var i = 0; i < results.rows.length; i++) {
      var splunkRecord = results.rows[i];
      Log.info("splunkRecord"+splunkRecord);
      if (splunkRecord && splunkRecord[rawRowIndex]) {
        var rawRecord = splunkRecord[rawRowIndex];        
    events.push(Util.splunkRecordToEvent(JSON.parse(rawRecord.replace(/\nValue of UseDynamoDB = True/g, ''))));
       }
    }
   Log.info("end splunck sear");
   Log.info('Splunk search completed, events count:'+events.length);
   h.response(Response.buildResponse(0, events));
  });

 

 

I can see the result or events in console with the search count (Splunk Search completed, events count: ) log as well. But I am getting 500 error as response through curl and postman too. What code changes I have to do to get the result data as response. Please suggest. Thank you

Labels (1)
Tags (1)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...