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!

Introducing the 2024 SplunkTrust!

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

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...