Dashboards & Visualizations

How to dynamically display the username of the current logged in user in the app navigation menu?

MaryvonneMB
Path Finder

Hi,

I would like to put the current username in the app navigation menu. New on Splunk and I don't understand everything.

I guess one way is to use a parameter in the default.xml file. For example:

<param name="search">search | rest /services/authentication/current-context | table username</param>

Found on this post:
https://answers.splunk.com/answers/338919/how-do-i-get-the-current-logged-in-username-in-spl.html
But I don't know how to set a view name dynamically.

I think it could be possible to use JavaScript, but I'm not very comfortable with it.

If someone can help me, it will be pretty cool (even with a JS solution if there's great explications ^^)

Cheers

0 Karma
1 Solution

MaryvonneMB
Path Finder

Finally, dealing with JS I find a solution:
I get the last 'a' tag, get the parent (li), duplicate and change children attribute I want. Then I append it to the last

  • .
  • var $str = $( ".nav-item.shared-appbar-navitem.nav-item-" ).find($('a[title="DECONNEXION"]'));              
    var $li=$str.parent();
    $topList=$li.clone()
    $topList.children().attr('href',"");
    $topList.children().attr('title',"USERNAME");                                                   $topList.children().text(nameShow);                                             
    $ul=$li.parent();   
    $topList.appendTo($ul);
    
    </li>
    

    View solution in original post

    0 Karma

    MaryvonneMB
    Path Finder

    Finally, dealing with JS I find a solution:
    I get the last 'a' tag, get the parent (li), duplicate and change children attribute I want. Then I append it to the last

  • .
  • var $str = $( ".nav-item.shared-appbar-navitem.nav-item-" ).find($('a[title="DECONNEXION"]'));              
    var $li=$str.parent();
    $topList=$li.clone()
    $topList.children().attr('href',"");
    $topList.children().attr('title',"USERNAME");                                                   $topList.children().text(nameShow);                                             
    $ul=$li.parent();   
    $topList.appendTo($ul);
    
    </li>
    

    0 Karma

    arunsundarm
    Engager

    I Could not paste this script in the dashboard and it gives an error, can someone give me steps on how to include this in the dashboard

    0 Karma

    gmontero
    Loves-to-Learn

    What kind of builder are you using for your dashboards?

    If it's dashboard studio, I believe it is not possible to render any dynamic JS content.

    With the classic dashboard panel I think it would be possible to do so.

    In this url you can check differences between both of them.

    Finally, you got the option with SPLUNK UI, where you can customize everything and in a dynamic way, but it requieres a huge effort for developing the whole solution.

    0 Karma

    rafamss
    Contributor

    Hi MaryvonneMB,

    For use this, the command must be like this only:

    | rest /services/authentication/current-context | table username

    Then, you put this inside your XML.

    0 Karma

    MaryvonneMB
    Path Finder

    Just like this, not in any specific tag?

    0 Karma

    jkat54
    SplunkTrust
    SplunkTrust

    Does the current location not suffice?

    alt text

    0 Karma

    arunsundarm
    Engager

    I believe The requirement is to display it in a custom dashboard and fetch similar data related to the username

    0 Karma

    MaryvonneMB
    Path Finder

    I work for a customer that want this in the nav menu =s (For me it's useless...)

    0 Karma
    Get Updates on the Splunk Community!

    What's new in Splunk Cloud Platform 9.1.2312?

    Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

    What’s New in Splunk Security Essentials 3.8.0?

    Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

    Let’s Get You Certified – Vegas-Style at .conf24

    Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...