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!

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...

Adoption of Infrastructure Monitoring at Splunk

  Splunk's Growth Engineering team showcases one of their first Splunk product adoption-Splunk Infrastructure ...