Splunk Search

Searchmanager cannot reuse in for loop in HTML dashboard

chrismok
Path Finder

Currently, my dashboard is basic on the number of the source
and generate the number of chart or table.

The structure is looks like that

   var search0=new searchmanager(......)

    search0.data('result').on('data',function(properties){
  //sudo code
   add  search0.data('result').data.row to source_array;
 //sudo code
    for(var row=1; row<=source_array.length; row++)
    {
       var search1=new searchmanager(....... "id":"search1".....)
        search1.data('result').on('data',function(properties){
            BuildInfo(search1.data('results').data().rows);
         }

    }
}

When I run, it. The first char can be generated, but loop to the second round. browser return an error message
Uncaught Error: Already have instance with id: search1 (mvc.js:6)
Uncaught TypeError: Cannot read property 'rows' of undefined (my javascript file, refer to line 10)

For the first error, I have a temp solution which modify the code which add the variable id for avoid the search id redundant

   var id=0;
    var search0=new searchmanager(......)

    search0.data('result').on('data',function(properties){
//sudo code
   add  search0.data('result').data.row to source_array;
 //sudo code
    for(var row=1; row<=source_array.length; row++)
    {
       var search1=new searchmanager(....... "id":"search"+(++id).....)
        search1.data('result').on('data',function(properties){
            BuildInfo(search1.data('results').data().rows);
         }

    }
}

But the bad side is if the number search manager will keep growing if user keep run the page without page load.
For the second error. I have no idea to fix.

Tags (2)

bmacias84
Champion

Hello,

I had very similar issue. I was able to work around the issue by using epoch and attaching it to my id. For the second issue you can set the timeout attribute in the search manager. The timeout specifies in seconds how long to keep the search after processing has stopped.


poolSearch = new SearchManager({
                        id: elementSearch+epoch,
                        autostart: "true",
                        latest_time: "now",
                        earliest_time: "-1d@d",
                        cache: 'false',
                        search: splunkQuery,
                        timeout: "5"
                    });

0 Karma

sumangala
Path Finder

With timeout: "5" setting doesn't resolve the issue. Is there any other way?

0 Karma

chrismok
Path Finder

Anyone meet this case?

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...