Dashboards & Visualizations

How do I consume tokens from the URL?

allan_newton
Path Finder

Hi,

I have a scenario where I have to consume tokens for my searches in the dashboard from the URL. I'm doing the dashboard building in HTML + javascript, say tokens are separated by "=" symbol.

Please help.

Tags (3)
0 Karma
1 Solution

thirumalreddyb
Communicator

I was discussing the same with a friend of mine a couple of hours back. I told him to consume the url and extract your fields. Below is the code for that.

Url = {
        get get(){
        var vars= {};
        if(window.location.href.length!==0)
            window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value){
                key=decodeURIComponent(key);
                if(typeof vars[key]==="undefined") {vars[key]= decodeURIComponent(value);}
                else {vars[key]= [].concat(vars[key], decodeURIComponent(value));}
            });
        return vars;
    }

Now you have all the fields and values. Store them into variables or concat them directly into search strings in your search manager as +Url.get.fieldname+

Hope this will serve you purpose.

View solution in original post

thirumalreddyb
Communicator

I was discussing the same with a friend of mine a couple of hours back. I told him to consume the url and extract your fields. Below is the code for that.

Url = {
        get get(){
        var vars= {};
        if(window.location.href.length!==0)
            window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value){
                key=decodeURIComponent(key);
                if(typeof vars[key]==="undefined") {vars[key]= decodeURIComponent(value);}
                else {vars[key]= [].concat(vars[key], decodeURIComponent(value));}
            });
        return vars;
    }

Now you have all the fields and values. Store them into variables or concat them directly into search strings in your search manager as +Url.get.fieldname+

Hope this will serve you purpose.

allan_newton
Path Finder

Worked like abraca dabra! Thank you.

0 Karma

jeffland
SplunkTrust
SplunkTrust

You simply use them on the second dashboard as you would on the first where you create them, splunk takes care of the magic behind that. This page should help you out further.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...