Dashboards & Visualizations

A custom JavaScript error caused an issue loading your dashboard. See the developer console for more details.

_pravin
Communicator

Hi, 

 

I get this error in our Splunk dashboards once I migrated splunk to version 9.2.2

I was able to bypass the error in the dashboards by updating internal_library_settings and unrestricting the library requirements. But this increases the risk/vulnerability of the environment. 

require(['jquery', 'underscore', 'splunkjs/mvc', 'util/console'], function($, _, mvc, console) {
    function setToken(name, value) {
        console.log('Setting Token %o=%o', name, value);
        var defaultTokenModel = mvc.Components.get('default');
        if (defaultTokenModel) {
            defaultTokenModel.set(name, value);
        }
        var submittedTokenModel = mvc.Components.get('submitted');
        if (submittedTokenModel) {
            submittedTokenModel.set(name, value);
        }
    }
    $('.dashboard-body').on('click', '[data-set-token],[data-unset-token],[data-token-json]', function(e) {
        e.preventDefault();
        var target = $(e.currentTarget);
        var setTokenName = target.data('set-token');
        if (setTokenName) {
            setToken(setTokenName, target.data('value'));
        }
        var unsetTokenName = target.data('unset-token');
        if (unsetTokenName) {
            setToken(unsetTokenName, undefined);
        }
        var tokenJson = target.data('token-json');
        if (tokenJson) {
            try {
                if (_.isObject(tokenJson)) {
                    _(tokenJson).each(function(value, key) {
                        if (value == null) {
                            // Unset the token
                            setToken(key, undefined);
                        } else {
                            setToken(key, value);
                        }
                    });
                }
            } catch (e) {
                console.warn('Cannot parse token JSON: ', e);
            }
        }
    });
});

The above code is the one that I have for one of the dashboards. Not sure how to check the jQuery version of the code, but if there is some help to fix the above code that meets the requirements of Jquery 3.5, I'll implement the same for other code as well.

 

Thanks,

Pravin

Labels (2)
Tags (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

That looks like it's the token setter JS from the dashboard examples.

However, you have

require(['jquery', 'underscore', 'splunkjs/mvc', 'util/console'], function($, _, mvc, console) {

whereas the original is

require(['jquery', 'underscore', 'splunkjs/mvc'], function($, _, mvc) {

have you tried removing the util/console and console declarations

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

That looks like it's the token setter JS from the dashboard examples.

However, you have

require(['jquery', 'underscore', 'splunkjs/mvc', 'util/console'], function($, _, mvc, console) {

whereas the original is

require(['jquery', 'underscore', 'splunkjs/mvc'], function($, _, mvc) {

have you tried removing the util/console and console declarations

 

_pravin
Communicator

Hi @bowesmana ,

 

Thanks for the response. I don't know JS, so I am checking with the communty if someone else had the same issues and might have some generic solution that might help me fix the xml.

I'll tried your solution and it worked.

Could you please explain what it really does so that I would get idea ?

 

Thanks,

Pravin

0 Karma

bowesmana
SplunkTrust
SplunkTrust

It's a really useful piece of JS that allows you to put HTML buttons into your dashboard that can set and unset tokens in use in the dashboard. 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

For example

      <html>
        <button data-token-json="{&quot;my_token&quot;:&quot;My Value&quot;">Set the my_token token to My Value</button>
      </html>

and you can then use the $my_token$ elsewhere in your dashboard.

0 Karma

_pravin
Communicator

Hi @bowesmana ,

 

I mean to ask what part of the js file defines the JS error in the UI. I have other files as well that have different functionalities but they do not have the util/console part but still throw the same error. How do I identify those parts in the JS file?

 

Regards,

Pravin

0 Karma

bowesmana
SplunkTrust
SplunkTrust

We you'll have to look on a case by case basis - there are some use cases where objects are defined in first JS load and then they can be reloaded, but the same object already exists the second time around.

Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In September, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...

New in Observability - Improvements to Custom Metrics SLOs, Log Observer Connect & ...

The latest enhancements to the Splunk observability portfolio deliver improved SLO management accuracy, better ...

Improve Data Pipelines Using Splunk Data Management

  Register Now   This Tech Talk will explore the pipeline management offerings Edge Processor and Ingest ...