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
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
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
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
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.
For example
<html>
<button data-token-json="{"my_token":"My Value"">Set the my_token token to My Value</button>
</html>
and you can then use the $my_token$ elsewhere in your dashboard.
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
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.