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!

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 ...