Dashboards & Visualizations

How can I use a token to set hideSplunkBar?

behudelson
Path Finder

Hello, I am trying to control the hideSplunkBar attribute using a token. Regardless of the token's value ("true", "false", 1, or 0) the attribute always evaluates to true and hides the Splunk Bar. If I don't use a token, the attribute behaves as expected. My use case is that I would like to hide the Splunk bar for a certain role. I have sample code below. Thank you for any input you may have!

 <form hideSplunkBar="$hideSplunkBar$">
           <search>
            <query>| search
        | table hidesplunkbar</query>
            <done>
               <eval token="hideSplunkBar">$result.hidesplunkbar$</eval>
            </done>
          </search>
    .
    .
    .
    </form>
0 Karma
1 Solution

niketn
Legend

@behudelson, your best option would be to create separate dashboards based on different roles and create your own dashboard with menu/link to specific dashboard for each user. Disable App Bar with default navigation from Splunk.

Please check the one of my older post on considerations for role based access in Splunk.
https://answers.splunk.com/answers/588779/whats-the-best-way-to-limit-a-role-so-it-only-has.html

I feel the approach you are referring to, with REST API for identifying logged in user through REST API, is the one from my older posts https://answers.splunk.com/answers/575377/can-i-restrict-permissions-for-the-text-box-drilld.html, where form inputs are displayed but disabled (PS: Disabling requirement is different from requirement of hiding inputs).

Hiding can be done directly via CSS. PS: Instead of using REST API I have used check box to demonstrate the functioning (however, like said earlier better approach is to have separate dashboards based on Role as stated earlier). Also following code has been tested in Splunk Enterprise 7 and should work with 6.6 as well. I am not sure about 6.5 or earlier version. If direct CSS does not work in any previous Splunk versions, then JS needs to be used similar to the answer link posted above.

alt text

Please find the run anywhere dashboard code in Simple XML (no additional static file required for this example code).

<form hideSplunkBar="false">
  <label>Hide Splunk Bar through Token</label>
  <fieldset submitButton="false">
    <input type="checkbox" token="tokShowSplunkBar" searchWhenChanged="true">
      <label></label>
      <choice value="showSplunkBar">Show Splunk Bar</choice>
      <change>
        <condition value="showSplunkBar">
          <set token="tokVisibility">visible</set>
          <set token="tokMiscCSSAppBarPosition">static</set>
          <set token="tokMiscCSSAppBarTop">auto</set>
        </condition>
        <condition>
          <set token="tokVisibility">hidden</set>
          <set token="tokMiscCSSAppBarPosition">relative</set>
          <set token="tokMiscCSSAppBarTop">-25px</set>
        </condition>
      </change>
    </input>
  </fieldset>
  <row depends="$alwaysHideCSSPanel$">
    <panel>
      <html>
        <style>
          header div.splunk-header div[class$="---2Izs_"]{
            visibility: $tokVisibility$ !important;
          }
          header div.splunk-header div[class$="---3EGL7"]{
            position:$tokMiscCSSAppBarPosition$ !important;
            top:$tokMiscCSSAppBarTop$ !important;
          }
        </style>
      </html>
    </panel>
  </row>
</form>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@behudelson, your best option would be to create separate dashboards based on different roles and create your own dashboard with menu/link to specific dashboard for each user. Disable App Bar with default navigation from Splunk.

Please check the one of my older post on considerations for role based access in Splunk.
https://answers.splunk.com/answers/588779/whats-the-best-way-to-limit-a-role-so-it-only-has.html

I feel the approach you are referring to, with REST API for identifying logged in user through REST API, is the one from my older posts https://answers.splunk.com/answers/575377/can-i-restrict-permissions-for-the-text-box-drilld.html, where form inputs are displayed but disabled (PS: Disabling requirement is different from requirement of hiding inputs).

Hiding can be done directly via CSS. PS: Instead of using REST API I have used check box to demonstrate the functioning (however, like said earlier better approach is to have separate dashboards based on Role as stated earlier). Also following code has been tested in Splunk Enterprise 7 and should work with 6.6 as well. I am not sure about 6.5 or earlier version. If direct CSS does not work in any previous Splunk versions, then JS needs to be used similar to the answer link posted above.

alt text

Please find the run anywhere dashboard code in Simple XML (no additional static file required for this example code).

<form hideSplunkBar="false">
  <label>Hide Splunk Bar through Token</label>
  <fieldset submitButton="false">
    <input type="checkbox" token="tokShowSplunkBar" searchWhenChanged="true">
      <label></label>
      <choice value="showSplunkBar">Show Splunk Bar</choice>
      <change>
        <condition value="showSplunkBar">
          <set token="tokVisibility">visible</set>
          <set token="tokMiscCSSAppBarPosition">static</set>
          <set token="tokMiscCSSAppBarTop">auto</set>
        </condition>
        <condition>
          <set token="tokVisibility">hidden</set>
          <set token="tokMiscCSSAppBarPosition">relative</set>
          <set token="tokMiscCSSAppBarTop">-25px</set>
        </condition>
      </change>
    </input>
  </fieldset>
  <row depends="$alwaysHideCSSPanel$">
    <panel>
      <html>
        <style>
          header div.splunk-header div[class$="---2Izs_"]{
            visibility: $tokVisibility$ !important;
          }
          header div.splunk-header div[class$="---3EGL7"]{
            position:$tokMiscCSSAppBarPosition$ !important;
            top:$tokMiscCSSAppBarTop$ !important;
          }
        </style>
      </html>
    </panel>
  </row>
</form>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

behudelson
Path Finder

niketnilay,

This is a fantastic solution. Thank you.

I didn't know that I could hide a row and add custom css from the style tag in a panel. Neat!!

Best,
Ben

0 Karma

niketn
Legend

@behudelson when the dashboard loads the Splunk Bar is supposed to be either loaded or hidden. Could you please describe your use case as to why you want to Show Dashboard with Splunk Bar and then hide based on results of your search query?

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

behudelson
Path Finder

The search query is actually independent from the content of the panels/dashboard. I am using rest to identify what roles the user is assigned to. If the user has a specific role, I want to hide the Splunk bar from them.

The use case is that I have business users who I want to prevent from seeing menus they don't need to see. More importantly, I do not want them to have search capabilities. However, if I remove search from the permissions or if I remove read access from the Search and Reporting app, they cannot see the dashboards do not run queries.

0 Karma

logloganathan
Motivator

Could you please modify the first line as follows
< form hideSplunkBar="$$hideSplunkBar$$">

0 Karma

behudelson
Path Finder

Hi logloganathan,

Thank you for assisting me!

The modification did not work. The Splunk bar is visible for both true and false values of the token. Also, I am getting a warning in the source editor for the top line "Non-boolean value "$$hideSplunkBar$$"" identified.

Best,
Ben

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...