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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...