Dashboards & Visualizations

Javascript: Running a cyclic lookup search forever

haph
Path Finder

Hi guys,

I'm currently developing a Dashboard for user interaction. 

We have a production machine with three work stations which are separated. 

Now every work station can stop the conveyor. 

We can't get the reason the conveyor stops automatically out of the machine so we want to digitize our worker knowledge (they see a faulty part for example). 

Every work station now has an own iPad where the HTML-dashboards are running. 

 

Out of a lookup I load the possible reasons why a worker at a certain station could have stopped the conveyor and display them accordingly on the dashboards just as red buttons. 

If a button is pressed a search is executed to store the work station, the stopping reason and the time in an index. Now all dashboards are locked (buttons deactivated) that nobody can set two reasons at once. One work station can start the conveyor again and on that dashboard the buttons are replaced with one big dismiss button which has to be pressed if the worker starts the conveyor again. 

 

This works as expected. 

Now, because of the separation of the work stations, they want to display the stop reason, work station and time of the current stop on all dashboards. 

To do this I implemented a second search which updates a lookup with the required information or deletes it. 

Now to my problem:

To display the information I run a cyclic search (with setTimeout(function, delay)). Now this works multiple times but then it just stops the execution of the cyclic search (as far as I know). 

Question:

How can I ensure to run the cyclic search forever? 

OR: 
Can I retrieve the lookup data in another way?

 

If you have questions to my question or I forgot to implement some info, please give me a note!

Splunk version: 7.3.3 

The code:

 

 

 

startCyclicSearch(10000); 

        function cyclicSearch(){
            console.log("Start zyklische Suche");
           
            searchReadST.settings.set("search", '| inputlookup Stoerung' + Linie.substr(Linie.length-1,1) + lookup + '.csv' );  
                
            searchReadST.startSearch();
        }

        function resetKommendGedrueckt(){
            kommendgedrueckt = false;
        }

        var aktStoerungArray;
        var aktStoerungResults = searchReadST.data("results"); // get the data from that search
        aktStoerungResults.on("data", function() {
            var tokens = mvc.Components.get("default");
            //console.log(aktStoerungResults.data().rows);
            aktStoerungArray = aktStoerungResults.data().rows;
            console.log("Arbeitsplatz: " + aktStoerungArray[0][0] + " " + aktStoerungArray[0][1] +  "  aktive Störung: " + aktStoerungArray[0][2] + "  Uhrzeit: " + aktStoerungArray[0][3]);

            if (!kommendgedrueckt){
                if (aktStoerungArray[0][0] == ""){
                    $("#aktSt").html("");
                    $("#row00").hide();
                    $(".btnKommend").prop("disabled", false);
                
                }
                else{
                    $("#aktSt").html(aktStoerungArray[0][0] + " " + aktStoerungArray[0][1] + ":  aktive Störung = " + aktStoerungArray[0][2] + "  Uhrzeit: " + aktStoerungArray[0][3]);
                    $("#row00").show();
                    $(".btnKommend").prop("disabled", true);
                                
                }
            }
            
            startCyclicSearch(2000);
        });
        
        var St;
        var counter = 0;
        // Eventlistener für Störungsbuttons registrieren
        document.addEventListener('click',function(e){
            
            if(e.target && $(e.target).hasClass("btnKommend")){
                console.log("Entering Kommend");
                clearTimeout(intervalID);
                kommendgedrueckt = true;
                // Sofort Button deaktivieren um nicht auf lookup warten zu müssen und versehentlich eine 2. Störung zu senden
                $(".btnKommend").prop("disabled", true);

                // Störung aus Button Text übernehmen
                St = e.target.innerHTML;
                
                // Suche starten --> Störung mit Timestamp und AP speichern in Summary index machinedata_w05_sum
                searchST.settings.set("search", mvc.tokenSafe('| makeresults 1 | eval area="Pulvertechnik", machine="inputDevicePulveranlagen", app="StörungenPulveranlagen" | eval Störung="'+ St +'" | eval action="kommend" | eval Arbeitsplatz="' + AP + '", Linie="' + Linie + '" | table _time area machine app Störung action Arbeitsplatz Linie | collect index="' + summaryIndex + '" testmode=f' ));  
                searchST.startSearch();
                
                // TODO: Remove the following line if it doesn't work
                searchST.finalize();
                //console.log("Suche ausgeführt  " + getFormattedDate());
                //console.log(searchST.id);
                searchST.settings.set("search", mvc.tokenSafe(''));
                // Störung in inputlookup schreiben --> Andere Dashboards können drauf zugreifen
                searchStoreST.settings.set("search",  mvc.tokenSafe('| makeresults 1| eval _time=strftime(_time, "%H:%M:%S") | eval Stoerung="'+ St +'" | eval Arbeitsplatz="' + AP + '", Linie="' + Linie + '" | outputlookup Stoerung' + Linie.substr(Linie.length-1,1) + lookup + '.csv '));
                searchStoreST.startSearch();
                
                $(".btnKommend").prop("disabled", true);
                
                setTimeout(resetKommendGedrueckt, 10000);
                startCyclicSearch(10000);
                
            }

 

 

 

Thanks alot!

Labels (1)
0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...