Dashboards & Visualizations

How do I know which token in a dashboard is not set?

David
Splunk Employee
Splunk Employee

I have a complicated dashboard, with javascript, many panels, and all kinds of things. Some of my panels sometimes show "Search is waiting for input..." but I don't know how to figure out which token is not set.

Is there something I can do in the javascript inspector that would help me figure out which token isn't being set?

0 Karma
1 Solution

David
Splunk Employee
Splunk Employee

Absolutely. First open up the Javascript Console: https://webmasters.stackexchange.com/a/77337

Then paste in the following:

var missing_tokens = []

for(var attribute in splunkjs.mvc.Components.attributes){
    if(splunkjs.mvc.Components.attributes.hasOwnProperty(attribute) && typeof splunkjs.mvc.Components.getInstance(attribute).lastError != "undefined" && splunkjs.mvc.Components.getInstance(attribute).lastError == "Search is waiting for input..."){
        console.log("I have a manager..", attribute, splunkjs.mvc.Components.getInstance(attribute).lastError)
        var search=splunkjs.mvc.Components.attributes[attribute].attributes.search.replace(/\$\$\S+\$\$/g, "")
        var myRegex = /\$(\S*)\$/g,
            matches,
            tokens = [];
        while (matches = myRegex.exec(search)) {
           if(typeof splunkjs.mvc.Components.getInstance("submitted").get(matches[1]) == "undefined"){
                if(!(matches[1] in missing_tokens)){
                    missing_tokens[matches[1]] = 0
                }
                missing_tokens[matches[1]]++
           }
        }
    }
}
for(var token in missing_tokens){
    console.log("We found ", missing_tokens[token], " searches that are missing ", token, "-- add it via splunkjs.mvc.Components.getInstance(\"submitted\").set(\"" + token + "\", \"\")")
}

The result will tell you how many searches are dependent on each token, and what you can manually do to set a token (for troubleshooting, or otherwise) also via the Javascript Console.

View solution in original post

David
Splunk Employee
Splunk Employee

Absolutely. First open up the Javascript Console: https://webmasters.stackexchange.com/a/77337

Then paste in the following:

var missing_tokens = []

for(var attribute in splunkjs.mvc.Components.attributes){
    if(splunkjs.mvc.Components.attributes.hasOwnProperty(attribute) && typeof splunkjs.mvc.Components.getInstance(attribute).lastError != "undefined" && splunkjs.mvc.Components.getInstance(attribute).lastError == "Search is waiting for input..."){
        console.log("I have a manager..", attribute, splunkjs.mvc.Components.getInstance(attribute).lastError)
        var search=splunkjs.mvc.Components.attributes[attribute].attributes.search.replace(/\$\$\S+\$\$/g, "")
        var myRegex = /\$(\S*)\$/g,
            matches,
            tokens = [];
        while (matches = myRegex.exec(search)) {
           if(typeof splunkjs.mvc.Components.getInstance("submitted").get(matches[1]) == "undefined"){
                if(!(matches[1] in missing_tokens)){
                    missing_tokens[matches[1]] = 0
                }
                missing_tokens[matches[1]]++
           }
        }
    }
}
for(var token in missing_tokens){
    console.log("We found ", missing_tokens[token], " searches that are missing ", token, "-- add it via splunkjs.mvc.Components.getInstance(\"submitted\").set(\"" + token + "\", \"\")")
}

The result will tell you how many searches are dependent on each token, and what you can manually do to set a token (for troubleshooting, or otherwise) also via the Javascript Console.

chadmedeiros
Path Finder

Great detailed answer. I tend to simply throw relevant tokens into the title or subtitle bar of each panel while developing. Any tokens that aren't set should be obvious.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...