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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...