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

@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

@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.

@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!

Splunk Forwarders and Forced Time Based Load Balancing

Splunk customers use universal forwarders to collect and send data to Splunk. A universal forwarder can send ...

NEW! Log Views in Splunk Observability Dashboards Gives Context From a Single Page

Today, Splunk Observability releases log views, a new feature for users to add their logs data from Splunk Log ...

Last Chance to Submit Your Paper For BSides Splunk - Deadline is August 12th!

Hello everyone! Don't wait to submit - The deadline is August 12th! We have truly missed the community so ...