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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...