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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Quantify Your Splunk Investment Impact: Introducing Savings Metrics to Value Insights

Building on the foundation established in our initial Value Insights releases, we are introducing the Savings ...

Event Series: Telemetry Pipeline Management

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...