Dashboards & Visualizations

Reference token in multiple dashboards

stephensibley
New Member

I have a trellis panel that shows the amount of errors per service. I have created an additional dashboard for each service that has errors. Each dashboard has the same name as the service, so when drilling down the URL is /app/search/$trellis.value$. I am using a custom time token for the master dashboard with the trellis panel.

Is it possible to reference that same custom time token in every drilled down dashboard? Right now, the custom time resets every time you drill down into a dashboard.

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Hi @stephensibley,

If you have some token that you want to have in most of your dashboard then you can add below dashboard.js in $SPLUNK_HOME/etc/apps/your-app/appserver/static.

require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
    ], function(mvc) {
        function setSessionValue(name, value) {
            try {
                if (typeof(localStorage) !== "undefined") {
                    localStorage.setItem(name, value);
                }
            } catch (error) {
                if (error == QUOTA_EXCEEDED_ERR) {
                    console.log("Error: Session Storage limit exceeds.");
                } else {
                    console.log("Error: Saving to session storage.");
                }
            }
        }

        function getSessionValue(name) {
            try {
                if (typeof(localStorage) !== "undefined") {
                    return localStorage.getItem(name);
                }
                return "";
            } catch (error) {
                console.log("Session Storage Error :GET: " + error);
                return "";
            }
        }

        var tokens = mvc.Components.get("default");
        var submitted = mvc.Components.get("submitted");

        token_value = getSessionValue("my_token");
        if(token_value !=""){
            tokens.set("my_token", token_value);
            submitted.set("my_token", token_value);
        }

        # on filter (token) change write function to set value on localStorage
        tokens.on("change:my_token", function(){
            setSessionValue("my_token", tokens.get("my_token");
        }
});

In my case the token name is my_token. No matter which dashboard I go wether I'm doing drilldown or go via navigation panel my_token will always have user selected value. Most importantly you do not require any change to your dashboards, but you might require to clear the browser and Splunk cache and restart the Splunk.

Hope this helps!!!

0 Karma
Get Updates on the Splunk Community!

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...