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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...