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!

Announcing Scheduled Export GA for Dashboard Studio

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

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...