Dashboards & Visualizations

Searchmanager executes search more than once, resulting in duplicate events

haph
Path Finder

Hi guys,

basically the title.
I couldn't find a solution here so I created this question.

I have a html dashboard with buttons for user input. If a button is pressed one search is started to write data into a summary index and another one is started to populate a lookup (for other instances of the dashboard to look at).
In other words one button press should result in one event in the summary index.

Now this works most of the time fine. But sometimes, I can't find a pattern, a button press results in two events with _time difference of 1 or 2 seconds.
The js is only executed once so this is not the problem.

Do you guys know a solution to my problem? I would be very happy!

I'm currently on Splunk 7.2.6 running local on my laptop (for developing). The dashboard is located in an app created by me.

Parts of the code used:

var searchST = new SearchManager({
            id: "STkommendSearch",
            autostart: "false",

        });

document.addEventListener('click',function(e){
            St = e.target.innerHTML;
            if(e.target && $(e.target).hasClass("btnKommend")){
            searchST.settings.set("search", mvc.tokenSafe('| makeresults | eval Störung="'+ St +'" | eval action="kommend" | eval Arbeitsplatz=tostring("$form.Arbeitsplatz$") | table _time Störung action Arbeitsplatz | collect index=summary' ));  
                searchST.startSearch();

}

});
0 Karma
1 Solution

haph
Path Finder

Adding

searchName.finalize();

after

searchName.startSearch();

seems to get rid of the problem. I couldn't make out any duplicate events after the change. Why it works... I don't know.

View solution in original post

haph
Path Finder

Adding

searchName.finalize();

after

searchName.startSearch();

seems to get rid of the problem. I couldn't make out any duplicate events after the change. Why it works... I don't know.

elewis1
Path Finder

This answer got me in the right direction and after struggling with it for a week, the solution for me was to never call startSearch() OR finalize().

Just calling 'settings.set("search": $searchquery) ', even with autostart set to false, would start the search.

Below were my steps

  1. Create SearchManager object without 'search' set.
  2. call settings.set("search" after user clicks OK on a confirmation box
  3. search:done would trigger after this even though startSearch() and finalize() were never called.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...