Splunk Dev

Querying in Node.js

hassaanalich296
New Member

I am trying to query and manipulate results of Splunk searches using node. I am using the oneshotSearch however, as I understand it isn't a function hence, it doesn't return anything and therefore, I am unable to access the updated values my global variable that I manipulate within the function. The question then is, how do I access the variables results outside service.oneshotSearch

 

 

var Splunk_2 = [{"Verification Code" : '', "Verification Number" : ''}]

// Run a oneshot search that returns the job's results
service.oneshotSearch(
    searchQuery,
    searchParams,
    function query_result (err, results) {
        // Display the results
        var rawIndex = results.fields.indexOf("_raw");                            
        // Print out each result and the key-value pairs we want
        for (var i = 0; i < results.rows.length; i++) {
           Splunk_2.push({"Verification Code": JSON.parse(results.rows[i][rawIndex]).data.message_body,
                         "Verification Number": JSON.parse(results.rows[i][rawIndex]).data.phone
        });
      }                           
   }
);

 

 

 

 

 

Labels (3)
0 Karma
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 ...