All Apps and Add-ons

Set a dashboard token based on the requestors url?

timgren
Path Finder

In a large environment with search heads in multiple locations, I would like to create a single dashboard that switches search queries values based on the search head URL.  This would allow us to have a single agnostic dashboard for multiple locations and/or environments. where the index values differ from one to the other. 

Such as:
https://splunk.NorthAmerica.Mycompany.com
https://splunk.EU.Mycompany.com
etc.

token value = $URL$

Where I can set the locale token as:
Locale=case($URL$ LIKE %NorthAmerica%, "NorthAmerica", $URL$ LIKE %EU%,Europe) 

Is there any build-in splunk value that reads the requesting URL? 
If not, how to construct a js that leverages the URLSearchParams() method to set the token? 

Labels (1)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@timgren 

Try this Javascript.

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc) {
    console.log("LAZY!!!");
    var defaultTokenModel = mvc.Components.get('default');
    var submittedTokenModel = mvc.Components.get("submitted");
    $(document).ready(function() {
        console.log(window.location.href);
        var url = window.location.href;
        var Locale = "AnyDefaultValue";
        if (url.match(/NorthAmerica/gi)) {
            Locale = "NorthAmerica";
        } else if (url.match(/EU/gi)) {
            Locale = "Europe";
        } else if (url.match(/Table/gi)) {
            Locale = "Table";
        }
        defaultTokenModel.set("Locale", Locale);
        submittedTokenModel.set(defaultTokenModel.toJSON());
    });
});

 

Thanks
KV


If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@timgren 

Try this Javascript.

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc) {
    console.log("LAZY!!!");
    var defaultTokenModel = mvc.Components.get('default');
    var submittedTokenModel = mvc.Components.get("submitted");
    $(document).ready(function() {
        console.log(window.location.href);
        var url = window.location.href;
        var Locale = "AnyDefaultValue";
        if (url.match(/NorthAmerica/gi)) {
            Locale = "NorthAmerica";
        } else if (url.match(/EU/gi)) {
            Locale = "Europe";
        } else if (url.match(/Table/gi)) {
            Locale = "Table";
        }
        defaultTokenModel.set("Locale", Locale);
        submittedTokenModel.set(defaultTokenModel.toJSON());
    });
});

 

Thanks
KV


If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

timgren
Path Finder

Outstanding!
Thank you.  I was unaware of window.location.href  

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...