Splunk Dev

SplunkJS Search Manager collects the same event twice.

hellosplunkit
Loves-to-Learn

Hi Splunkers,
I'm on Splunk Enterprise 7.2.6.
i launch a javascript SearchManager to show some data on console.
Unfortunately it shows the data twice.i don't know why. i had saw the others answer
https://answers.splunk.com/answers/659188/splunkjs-search-manager-collect-twice-same-event.html
but it didn't work. help me ,thank you very much.

setInterval(function () {
var searchManagerInstance = MVC.Components.get("searchManager3");
if (searchManagerInstance != undefined && searchManagerInstance != null && searchManagerInstance != "") {
searchManagerInstance.startSearch();
var searchResult = searchManagerInstance.data("results");
console.log(searchResult);
/* searchResult.on("data", function() {
console.log("Has data? ", searchResult.hasData());
console.log("Data (rows): ", searchResult.data().rows);
console.log("Backbone collection: (rows) ", searchResult.collection().raw.rows);
});*/
searchResult.on("data", function () {
console.log("hello world");
})
}else{
var searchManager1 = new SearchManager(
{
id: "searchManager3",
preview: "true",
cache: "false",
data : "results",
search: "index=_internal (sourcetype=splunkd OR sourcetype=splunkd_access OR sourcetype=splunk_web_access OR sourcetype=splunkd_ui_access OR sourcetype=splunk_web_service) earliest=-5m@m latest=@m |stats count by sourcetype"
}
);
}
},2000);

Labels (1)
0 Karma

DavidHourani
Super Champion

Hi @hellosplunkit,

Check out your console.logcommands, you have :

console.log(searchResult);

And

console.log("Data (rows): ", searchResult.data().rows);

That could be what's causing the duplication. Easiest solution would be to get rid of all the console.log and start adding them one by one to see where you get the issue. Once that is identified it should be easy to deduplicate the results.

Cheers,
David

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...