Dashboards & Visualizations

How to conditionally display HTML panels with a token, set via a javascript program?

snipedown21
Path Finder

I have a fair idea that depends="$token$" can be used to display or hide the panel. My requirement is that I get the list of roles for a user, via a Javascript file, and load it onto tokens present on the dashboard.

Now, these tokens will be set to "null" when the dashboard initially loads, and from the script, set to the role value.

The dashboard itself is filled with panels which I need to conditionally display based on the roles returned from the search.

Here is some code I have put together:

<dashboard script="set_permissions.js" hideFooter="true" hideSplunkBar="true" hideEdit="false">
  <label>Title</label>
  <description>trying to render based on token setting from JS</description>
  <fieldset submitButton="false">
    <input type="dropdown" token="role1"></input>
  </fieldset>
  <row>
    <panel depends="$role1$">
      <html src="content.html">
      </html>
    </panel>
  </row>
</dashboard>

I also have CSS attached to the dashboard
And, here is the JS code:

require([
     "jquery",
     "splunkjs/mvc",
     "splunkjs/mvc/simplexml/ready!"
     ], function(
         $,
        mvc
     ) {
        var tokens = mvc.Components.get("default");
        var permissionGrant = "power";
    tokens.set("role1", permissionGrant);
     });

So, summarizing, the JS will set the token "role1" with a value from a search(In the example I have hardcoded the value).
The panel will then make a request and get the relevant HTML page and render it.

Thanks in advance.
Splunk for Life 🙂

Tags (1)
0 Karma
1 Solution

niketn
Legend

@snipedown21, seems like you need to setup role based access/display in Splunk Dashboard using JavaScript. Refer to one of my older answers on similar lines which you can re-use as per your use case: https://answers.splunk.com/answers/575377/can-i-restrict-permissions-for-the-text-box-drilld.html

Kindly try out and let us know if you need further assistance.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@snipedown21, seems like you need to setup role based access/display in Splunk Dashboard using JavaScript. Refer to one of my older answers on similar lines which you can re-use as per your use case: https://answers.splunk.com/answers/575377/can-i-restrict-permissions-for-the-text-box-drilld.html

Kindly try out and let us know if you need further assistance.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

snipedown21
Path Finder

@niketnilay, the link provides exactly what I need. Thank you for the super fast and accurate response.
There was really no need for javascript.

niketn
Legend

@snipedown21 I have converted my comment to answer. Please accept the same to mark this as answered!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

Using the Splunk Threat Research Team’s Latest Security Content

REGISTER HERE Tech Talk | Security Edition Did you know the Splunk Threat Research Team regularly releases ...

SplunkTrust | 2024 SplunkTrust Application Period is Open!

It's that time again, folks! That's right, the application/nomination period for the 2024 SplunkTrust is ...