Splunk Dev

Java SearchManager condition execution of function

yogip86
Explorer

I am working with JavaSDK to execute custom python script.  In below code, i want to execute errorfunc (highlighted) in case "myResults.on("data", function ()" even is not triggered. How i can put non event condition. 

require([
'underscore',
'jquery',
'splunkjs/mvc',
"splunkjs/mvc/searchmanager",
'splunkjs/mvc/simplexml/ready!'
], function (_, $, mvc, SearchManager) {
console.log("sample.js has been loaded");
buttonClick()

function buttonClick(){
$("#run_search_btn").on("click",function(){
console.log("Clicked")
$('#run_search_btn').attr( "disabled", "disabled" );

script1 = "| script XPDM_Creation"

function success(val_cnt,val){
console.log("Search Result: Successful");
console.log("Result:",val_cnt);
console.log(val);
alert("Generated");
$("#run_search_btn").removeAttr( "disabled");
}
function err(){
console.log("Search Result: Failed");
alert("Generation Failed")
$("#run_search_btn").removeAttr( "disabled");
}

runScript1(script1,success,err)

})
}


function runScript1(script1, successfunc, errorfunc) {
var result = [];
var lookupSearch = new SearchManager({
earliest_time: "-24h@h",
latest_time: "now",
search: script1
});
var myResults = lookupSearch.data("results");

lookupSearch.on("search:done", function () {
console.log(myResults)
myResults.on("data", function () {
result_cnt = myResults.data().rows;
myResults_text = myResults.data().rows[0][0];
successfunc(result_cnt,myResults_text)
})
errorfunc()
});


lookupSearch.on('search:failed', function(properties) {
// Print the entire properties object
console.log("FAILED:", properties);
errorfunc()
});

lookupSearch.on('search:error', function(properties) {
// Print the entire properties object
console.log("FAILED:", properties);
errorfunc()
});

lookupSearch.on('search:progress', function(properties) {
// Print just the event count from the search job
console.log("IN PROGRESS.\nEvents so far:", properties.content.eventCount);

});


}
})

Labels (4)
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...