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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...