Dashboards & Visualizations

How to disable search run in js on page load?

haph
Path Finder

Hi,

I created a html-dashboard in which the user can choose a work station and then can click buttons for several machine faults.
If a button is pressed, a search is started in js to write the fault, the time and if the fault is coming or going to a summary index.

This is the js code from one button:

 mysearch1_K = new SearchManager({
            id: "button1_K",
            autostart: "false",
            search: mvc.tokenSafe('| makeresults | eval Störung="Störung1" | eval action="kommend" | eval Arbeitsplatz=tostring("$form.Arbeitsplatz$") | table _time Störung action Arbeitsplatz | addinfo | collect index=summary' )
        });
        $(".button1_K").on("click", function (){

            console.log(tokens.get("form.Arbeitsplatz"));


            //alert('Ausgeführt Störung 1 kommend');
            console.log("Störung1 kommend");


            //console.log(mysearch1_K.get("search"));
            mysearch1_K.startSearch();


            $(this).prop("disabled", true);

            $(".button1_G").prop("disabled", false);

        });

This is the html "code":

<div id="row1" class="dashboard-row dashboard-row1">
        <div id="panel2" class="dashboard-cell" style="width: 50%;">
            <div class="dashboard-panel clearfix">

                <div class="panel-element-row">
                    <div id="element2" class="dashboard-element html" style="width: 100%">
                        <div class="panel-body html">
                                <div>
                                    <button class="btn btn-primary button1_K btnKommend btnST">St&#246;rung 1 kommend</button>
                                    <p>Beschreibung Störung</p>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

You see that i have set the searchmanager property "autostart = false" in the code. But it runs every search (for 14 buttons like the code above) when loading the page.
Did I miss something?

Thanks!

0 Karma
1 Solution

haph
Path Finder

Found the solution or cause by myself.

When declaring the Searchmanager with the search string:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false",
             search: mvc.tokenSafe('| makeresults | eval Störung="Störung1" | eval action="kommend" | eval Arbeitsplatz=tostring("$form.Arbeitsplatz$") | table _time Störung action Arbeitsplatz | addinfo | collect index=summary' )

the search is executed even with 'autostart: "false"'.
If I don't specify the search string in the declaration, the search is not executed:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false"

View solution in original post

0 Karma

robertlynch2020
Motivator

HI

 

Do you think you could publish the fill javascript for your answer, please.

 

Regards

Robert

0 Karma

robertlynch2020
Motivator

HI - I am new to java script can you post the full file please as i am having issues  understanding the before and after.

0 Karma

haph
Path Finder

Found the solution or cause by myself.

When declaring the Searchmanager with the search string:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false",
             search: mvc.tokenSafe('| makeresults | eval Störung="Störung1" | eval action="kommend" | eval Arbeitsplatz=tostring("$form.Arbeitsplatz$") | table _time Störung action Arbeitsplatz | addinfo | collect index=summary' )

the search is executed even with 'autostart: "false"'.
If I don't specify the search string in the declaration, the search is not executed:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false"
0 Karma

rishavvaidya
Explorer

Hi Haph,

I'm facing the same issue. can you tell me if we can not include search in searchManager then where else we can include it.

0 Karma

haph
Path Finder

Hi rishavvaidya,

you first declare the searchmanager like in my answer above.
Then, when you want to execute the search you first set the search string and then start the search:

 // Setting search string
searchST.settings.set("search", mvc.tokenSafe('| makeresults 1| eval Störung="'+ St +'" | eval action="kommend" | eval temp=split(tostring("$form.Arbeitsplatz$"),"_") | eval Arbeitsplatz=mvindex(temp,0) | eval Linie=mvindex(temp,1) | fields - temp | table _time Störung action Arbeitsplatz Linie | collect index=summary' ));  

// Starting search
searchST.startSearch();

And if it is important that the search exactly executed once (in my use case because the search writes a button press into the index and I want to count the presses and multiply search executions results in multiple indexed button presses instead of one) then you have to add the following after the xxx.startSearch();:

searchST.finalize();
0 Karma
Get Updates on the Splunk Community!

.conf24 | Day 0

Hello Splunk Community! My name is Chris, and I'm based in Canberra, Australia's capital, and I travelled for ...

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...