Dashboards & Visualizations

how to dynamically display the username in an input ?

mah
Builder

Hi, 

I tried to set an input which displays the name of the user who open the dashboard. 

I tried a dropdown input  where the default is my username and it works well : 

mah_0-1615823673103.png

But my username appears when other user open the dashboard with their own username (they have both mine and theirs), instead only theirs. 

So I checked the code, and what I found is when I select mine as default, it retained mine in the code :

<input type="dropdown" token="user_tok" searchWhenChanged="true">
<label>your username is :</label>
<fieldForLabel>username</fieldForLabel>
<fieldForValue>username</fieldForValue>
<search>
<query>| rest /services/authentication/current-context splunk_server=local
| fields roles username
| mvexpand roles
| fields username</query>
</search>
<change>
<condition match="isnotnull($value$) AND $value$!=&quot;&quot;">
<set token="tokTextFilter">$value$</set>
</condition>
</change>
<default>gxxxx</default>

 

mah_1-1615824133816.png

I tried to set the token input in the default : 

<default>$user_tok$</default>

But nothing changed.

How can I set by default and displays only the username who goes to the dashboard ? 

Thanks for your help !

Labels (1)
0 Karma

Vardhan
Contributor

Hi,

Can you try the below one.

<input type="dropdown" token="user">
<label>field1</label>
<prefix>user_token</prefix>
<fieldForLabel>username</fieldForLabel>
<fieldForValue>username</fieldForValue>
<search>
<query>| rest /services/authentication/current-context splunk_server=local
| fields roles username
| mvexpand roles
| fields username</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
</search>
</input>

0 Karma

mah
Builder

I tried your code, but it gave me this :

mah_0-1615882829598.png

What I want is to have automatically the username selected by default, and not to click on "Select". 

That's why I tried to put the token into the <default> value, but it does not work at all. 

I use this user token in multiple queries on my dashboard, and since there is only one value for a user then I would like this value to be the default.

0 Karma
Get Updates on the Splunk Community!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...