<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use global tokens in SPL in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319911#M20604</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;
When you are searching for user1 you need to wrap value in quotes by writing &lt;CODE&gt;$token_name|s$&lt;/CODE&gt; It will ensures that quotation marks surround the value referenced by the token.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval user1 = $env:user|s$ | eval user = case(user1  == "admin","hello admin",1==1,"hello user")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Jan 2018 09:47:52 GMT</pubDate>
    <dc:creator>493669</dc:creator>
    <dc:date>2018-01-19T09:47:52Z</dc:date>
    <item>
      <title>Use global tokens in SPL</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319907#M20600</link>
      <description>&lt;P&gt;Hi Guys&lt;/P&gt;

&lt;P&gt;I am trying to load searches based upon the logged user - In this way one dashboard can suffice the need for user based data access. I know that we can access the global tokens $env:user$ or $env:user_realname$ etc in the panel titles or html panels - for instance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel&amp;gt;
  &amp;lt;html&amp;gt;
    &amp;lt;p&amp;gt;Currently Logged In User: $env:user$&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;Full name of logged in user: $env:user_realname$&amp;lt;/p&amp;gt;
  &amp;lt;/html&amp;gt;
&amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but when I try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval user1 = $env:user$ | eval user = case($env:user$ == "admin","hello admin",1==1,"hello user")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It doesn't seem to work in simple xml. Any solution for that? I am on Splunk Cloud so don't have much room to play with .js files with simple xml. &lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 00:52:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319907#M20600</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2018-01-19T00:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Use global tokens in SPL</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319908#M20601</link>
      <description>&lt;P&gt;try wrapping your token in single quotes in your case statement, case('$env:user$' == "admin"&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 01:07:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319908#M20601</guid>
      <dc:creator>davpx</dc:creator>
      <dc:date>2018-01-19T01:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Use global tokens in SPL</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319909#M20602</link>
      <description>&lt;P&gt;Nope. Already tried it... &lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 01:13:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319909#M20602</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2018-01-19T01:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Use global tokens in SPL</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319910#M20603</link>
      <description>&lt;P&gt;hey try this run anywhere XML and you can take it as a reference to build yours.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
    &amp;lt;label&amp;gt;Default Environment Tokens&amp;lt;/label&amp;gt;
    &amp;lt;description&amp;gt;Global default environment tokens available on initial load, and can be used throughout the page.&amp;lt;/description&amp;gt;
    &amp;lt;row&amp;gt;
        &amp;lt;panel&amp;gt;
            &amp;lt;html&amp;gt;
                &amp;lt;h1&amp;gt;Hello, $env:user_realname$!&amp;lt;/h1&amp;gt;
            &amp;lt;/html&amp;gt;
            &amp;lt;table&amp;gt;
                &amp;lt;title&amp;gt;Login Attempts in the Last 24 Hours (for user="$env:user$")&amp;lt;/title&amp;gt;
                &amp;lt;search&amp;gt;
                    &amp;lt;query&amp;gt;index=_audit action="login attempt" user=$env:user|s$ | table _time user action info&amp;lt;/query&amp;gt;
                    &amp;lt;earliest&amp;gt;-24h&amp;lt;/earliest&amp;gt;
                    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
                &amp;lt;/search&amp;gt;
            &amp;lt;/table&amp;gt;
            &amp;lt;html depends="$env:is_enterprise$"&amp;gt;
                &amp;lt;i class="icon icon-info"/&amp;gt;
                &amp;lt;span&amp;gt;This is only visible in Splunk Enterprise and hidden in Splunk Lite, Splunk Free, etc.&amp;lt;/span&amp;gt;
            &amp;lt;/html&amp;gt;
        &amp;lt;/panel&amp;gt;
    &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also your query looks dicy, you can try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval user1=$env:user|s$ | eval user = case(user1="admin","hello admin",1==1,"hello user")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your query, you are assigning &lt;CODE&gt;token-value&lt;/CODE&gt; to &lt;CODE&gt;user1&lt;/CODE&gt; then you are using &lt;CODE&gt;token-value&lt;/CODE&gt; in &lt;CODE&gt;eval-case&lt;/CODE&gt; instead you should use &lt;CODE&gt;user1&lt;/CODE&gt; field. &lt;/P&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 08:39:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319910#M20603</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-19T08:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use global tokens in SPL</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319911#M20604</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
When you are searching for user1 you need to wrap value in quotes by writing &lt;CODE&gt;$token_name|s$&lt;/CODE&gt; It will ensures that quotation marks surround the value referenced by the token.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval user1 = $env:user|s$ | eval user = case(user1  == "admin","hello admin",1==1,"hello user")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jan 2018 09:47:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319911#M20604</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-01-19T09:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Use global tokens in SPL</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319912#M20605</link>
      <description>&lt;P&gt;Thanks mayurr98&lt;/P&gt;

&lt;P&gt;I've tried the code and query you provide, but as I stated in my question - the env tokens work fine with panel labels or in html panels however it doesn't work in SPL queries. Hence this part doesn't work form me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
           &amp;lt;query&amp;gt;index=_audit action="login attempt" user=$env:user|s$ | table _time user action info&amp;lt;/query&amp;gt;
           &amp;lt;earliest&amp;gt;-24h&amp;lt;/earliest&amp;gt;
           &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
 &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm using Splunk 6.6 in Cloud.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 07:41:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319912#M20605</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2018-01-22T07:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Use global tokens in SPL</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319913#M20606</link>
      <description>&lt;P&gt;Well this is not achievable as tokens are only visible in Simple XML not in SPL. However, a workaround would be to get the user form an API call:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rest /services/authentication/current-context splunk_server=local | fields username
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Once you have the user name you can apply the search commands on or using the username&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 00:23:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Use-global-tokens-in-SPL/m-p/319913#M20606</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2018-02-05T00:23:56Z</dc:date>
    </item>
  </channel>
</rss>

