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
Super Champion

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!

Admin Your Splunk Cloud, Your Way

Join us to maximize different techniques to best tune Splunk Cloud. In this Tech Enablement, you will get ...

Cloud Platform | Discontinuing support for TLS version 1.0 and 1.1

Overview Transport Layer Security (TLS) is a security communications protocol that lets two computers, ...

New Customer Testimonials

Enterprises of all sizes and across different industries are accelerating cloud adoption by migrating ...