<?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 POST LOGIN need to execute a search and use token across dashboard in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285976#M176713</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;For a particular filter which is used across my dashboard , I have run a search in javascript and set a token and use it .&lt;/P&gt;

&lt;P&gt;This search has to be run post login. &lt;BR /&gt;
 1. WHere can run such search in javascript&lt;BR /&gt;
 2. Need to set token in that javascript function and has to be used across dashboard ( like a global variable).&lt;/P&gt;

&lt;P&gt;Please give me inputs its kind of urgent requirement.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Prathi&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2016 06:00:31 GMT</pubDate>
    <dc:creator>prathikpisplunk</dc:creator>
    <dc:date>2016-09-16T06:00:31Z</dc:date>
    <item>
      <title>POST LOGIN need to execute a search and use token across dashboard</title>
      <link>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285976#M176713</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;For a particular filter which is used across my dashboard , I have run a search in javascript and set a token and use it .&lt;/P&gt;

&lt;P&gt;This search has to be run post login. &lt;BR /&gt;
 1. WHere can run such search in javascript&lt;BR /&gt;
 2. Need to set token in that javascript function and has to be used across dashboard ( like a global variable).&lt;/P&gt;

&lt;P&gt;Please give me inputs its kind of urgent requirement.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Prathi&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 06:00:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285976#M176713</guid>
      <dc:creator>prathikpisplunk</dc:creator>
      <dc:date>2016-09-16T06:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: POST LOGIN need to execute a search and use token across dashboard</title>
      <link>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285977#M176714</link>
      <description>&lt;P&gt;Hi @Prathikpisplunk,&lt;/P&gt;

&lt;P&gt;If you already have the &lt;CODE&gt;mvc&lt;/CODE&gt; components loaded:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function(mvc) {

    ...

});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can use tokens &lt;A href="http://dev.splunk.com/view/SP-CAAAEW3"&gt;directly&lt;/A&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;// Access the "default" token model
var tokens = mvc.Components.get("default");

// Retrieve the value of a token $mytoken$
var tokenValue = tokens.get("mytoken");

// Change the value of a token $mytoken$
tokens.set("mytoken", "this is the new value");
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Another example from &lt;A href="http://dev.splunk.com/view/SP-CAAAEWY"&gt;here&lt;/A&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;new DropdownView({
    id: "selIndex",
    value: mvc.tokenSafe("$indexName$"),
    el: $("#selIndex")
}).render();

new TextInputView({
    id: "txtKeywords",
    value: mvc.tokenSafe("$keywords$"),
    el: $("#txtKeywords")
}).render();

new SearchManager({
    id: "mySearch",
    search: mvc.tokenSafe("index=$indexName$ $keywords$")
});
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Sep 2016 15:55:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285977#M176714</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2016-09-19T15:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: POST LOGIN need to execute a search and use token across dashboard</title>
      <link>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285978#M176715</link>
      <description>&lt;P&gt;Hi Xander, &lt;/P&gt;

&lt;P&gt;Thanks for the reply. I have created one js file and running a search in that and setting the token.&lt;BR /&gt;
Now I am planning to include this js file in all the xml files which are in my dashboard. There are about 20 xml files. So it is not a right thing to include in all 20.  Also the search in js wil run 20 times based on user clicking each panel. so I wanted to know if there is any post login javascript function where I can just run the javascript function only once and set the token which can later be used globally?&lt;/P&gt;

&lt;P&gt;-----------------Below is the javascript funtion where I am trying to see if user has admin rights. based on which in xml I need to show him the drop down options--------------&lt;BR /&gt;
function(mvc, SearchManager) {&lt;BR /&gt;
    var userSearch = new SearchManager({&lt;BR /&gt;
                    "id": "userSearch",&lt;BR /&gt;
                    "preview": "false",&lt;BR /&gt;
                    "cache": "false",&lt;BR /&gt;
                    "search": "|rest splunk_server=local /services/authentication/current-context |table roles |mvexpand roles"&lt;BR /&gt;
                    }, {tokens: false});&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    userSearch.startSearch();
    var roleSearchResults = userSearch.data('results');
    roleSearchResults.on("data", function() {    
        var userRoles = roleSearchResults.data().rows;
        var tokens = mvc.Components.get("default");    
        tokens.set('RoleCheckQuery', "");        
        for(var i=0; i&amp;lt;userRoles.length; i++){
            console.log(userRoles[i][0]); 
              var userRole = userRoles[i][0];
            if (userRole === "admin" ) {
                tokens.set('RoleCheckQuery', "");
                break;
                    } 
            else {
                 tokens.set('RoleCheckQuery', '| join cpyKey[| rest /services/authentication/current-context|search (NOT username=\"splunk-system-user\") | fields + roles | mvexpand roles| makemv roles delim="-" | eval cpyKey=mvindex(roles, 3)|fields cpyKey]');
                  }
        }
        var tokenValue = tokens.get("RoleCheckQuery");

    });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Sep 2016 18:59:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285978#M176715</guid>
      <dc:creator>prathikpisplunk</dc:creator>
      <dc:date>2016-09-19T18:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: POST LOGIN need to execute a search and use token across dashboard</title>
      <link>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285979#M176716</link>
      <description>&lt;P&gt;One thing you could do is output the token to lookup and then load it from the lookup in the other dashboards?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 20:07:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/POST-LOGIN-need-to-execute-a-search-and-use-token-across/m-p/285979#M176716</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2016-09-21T20:07:08Z</dc:date>
    </item>
  </channel>
</rss>

