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>
    

    View solution in original post

    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

    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
    .conf21 CFS Extended through 5/20!

    Don't miss your chance
    to share your Splunk
    wisdom in-person or
    virtually at .conf21!

    Call for Speakers has
    been extended through
    Thursday, 5/20!