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!

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 ...