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!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...