<?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: REST and javascript not working in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61441#M12231</link>
    <description>&lt;P&gt;I think I am very close to solving my ultimate objective.&lt;BR /&gt;
Which is obtaining the user name of the user logged in so I can customize dashboards based on the user logged in.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://splunk-base.splunk.com/answers/28869/my-username-in-the-dashboard"&gt;http://splunk-base.splunk.com/answers/28869/my-username-in-the-dashboard&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks for all the help so far.&lt;/P&gt;</description>
    <pubDate>Sun, 21 Aug 2011 00:42:00 GMT</pubDate>
    <dc:creator>jgauthier</dc:creator>
    <dc:date>2011-08-21T00:42:00Z</dc:date>
    <item>
      <title>REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61434#M12224</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;

&lt;P&gt;I am working with the REST API, and have had some success from the command line.&lt;BR /&gt;
For instance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -u user:password -k &lt;A href="https://s-splunk:8089/services/search/jobs" target="test_blank"&gt;https://s-splunk:8089/services/search/jobs&lt;/A&gt; -d"search=savedsearch%20Blocked_Sites"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Works. I can see the job running in the jobs.  I can pull the stats, and results as well.&lt;/P&gt;

&lt;P&gt;However, when I take this same thing and apply it in application.js, the search does not run.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if (Splunk.util.getCurrentView()=="request_search") {
     $.ajax({
        url: 'https://s-splunk:8089/services/search/jobs', 
        type: 'POST', 
        data: 'search=savedsearch%20Blocked_Sites',
        success: function(){
        var messenger = Splunk.Messenger.System.getInstance();
            messenger.send('info', 'splunk', "Job is running....");
        }
     });
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It is returning 'success', as the info bar in splunk says, 'Job is running....'.&lt;/P&gt;

&lt;P&gt;Am I missing something?&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2011 01:32:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61434#M12224</guid>
      <dc:creator>jgauthier</dc:creator>
      <dc:date>2011-08-20T01:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61435#M12225</link>
      <description>&lt;P&gt;Although there are some exceptions if you can get people to configure their browsers differently, in general you will not be able to talk to the 8089 port from anything that loaded from the 8000 port.  Although it's only the port that's different, the browser will treat this as any other cross-domain scripting attempt and it'll block it. &lt;/P&gt;

&lt;P&gt;Fortunately there are many better ways to do this sort of thing from Javascript.  the Splunk UI contains many classes that it uses to talk to the backend.  You can see them here.  &lt;A href="http://dev.splunk.com/view/app-framework-reference/SP-CAAADQF"&gt;http://dev.splunk.com/view/app-framework-reference/SP-CAAADQF&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In particular, the Search object is probably what you're looking for. &lt;BR /&gt;
&lt;A href="http://dev.splunk.com/view/SP-CAAADQV"&gt;http://dev.splunk.com/view/SP-CAAADQV&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Assuming you have two handler functions, onSuccess and onFailure, you'd use it to dispatch a search like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var search = new Splunk.Search("foo bar | stats count");
var range = new Splunk.TimeRange("-24h@h","now")
search.setTimeRange(range);
search.dispatchJob(onSuccess, onFailure);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As to what to do with the thing then, well that's another story entirely.... If an instance of Splunk.Jobber exists in the page, then it will notice the dispatch and start polling the backend for progress on the Job, triggering progress and done events as appropriate.  On the other hand if the Jobber is not there, then you'll have to write your own polling code to do the same thing. &lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2011 03:24:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61435#M12225</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2011-08-20T03:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61436#M12226</link>
      <description>&lt;P&gt;Brings up at least two points.  There needs to be reference for jobber.js, popup.js, and maybe more (need more time).  Also need to be higher level topics such as how events are handled, better know a view's hierarchy, and so on.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2011 05:19:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61436#M12226</guid>
      <dc:creator>araitz</dc:creator>
      <dc:date>2011-08-20T05:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61437#M12227</link>
      <description>&lt;P&gt;Indeed. The phrase "no REST for the wicked" certainly springs to mind.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2011 06:36:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61437#M12227</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2011-08-20T06:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61438#M12228</link>
      <description>&lt;P&gt;That's great! Thanks!&lt;BR /&gt;
I will try that for searches.  The pain behind this is that I am trying to access REST endpoints &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;
Unless there is a javascript module, I will have to do it this way somehow.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2011 12:34:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61438#M12228</guid>
      <dc:creator>jgauthier</dc:creator>
      <dc:date>2011-08-20T12:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61439#M12229</link>
      <description>&lt;P&gt;Well if you're trying to interact with the search API, I'd say the JS objects are still the way to go.  If you need to hit other parts of the overall REST API,  you should look at the /splunkd proxy.  If you go to http://&lt;A href="host:port"&gt;host:port&lt;/A&gt;/paths , you will see an intriguing path called /splunkd. Although this may dissappear in future versions, it offers a complete GET access to splunkd's endpoints.  If you need to POST however you're out of luck, although I think there's some conf setting to even enable that.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2011 21:12:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61439#M12229</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2011-08-20T21:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61440#M12230</link>
      <description>&lt;P&gt;This is great!  But I can't get it to work.&lt;BR /&gt;
I can review the results of a search using this method:&lt;BR /&gt;
&lt;A href="http://host:8000/en-US/splunkd/search/jobs/1313884823.2/results_preview"&gt;http://host:8000/en-US/splunkd/search/jobs/1313884823.2/results_preview&lt;/A&gt;&lt;BR /&gt;
Anything else gives me an error:&lt;BR /&gt;
Error loading stylesheet: A network error occured loading an XSLT stylesheet:&lt;BR /&gt;
&lt;A href="http://host:8000/static/atom.xsl"&gt;http://host:8000/static/atom.xsl&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;REST endpoints through 8089 for searching begins with /services.  When using /splunkd it does not?&lt;/P&gt;

&lt;P&gt;I get that error using either:&lt;BR /&gt;
&lt;A href="http://host:8000/en-US/splunkd/services/authentication/current-context/context"&gt;http://host:8000/en-US/splunkd/services/authentication/current-context/context&lt;/A&gt;&lt;BR /&gt;
OR&lt;BR /&gt;
&lt;A href="http://host:8000/en-US/splunkd/authentication/current-context/context"&gt;http://host:8000/en-US/splunkd/authentication/current-context/context&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Aug 2011 00:40:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61440#M12230</guid>
      <dc:creator>jgauthier</dc:creator>
      <dc:date>2011-08-21T00:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61441#M12231</link>
      <description>&lt;P&gt;I think I am very close to solving my ultimate objective.&lt;BR /&gt;
Which is obtaining the user name of the user logged in so I can customize dashboards based on the user logged in.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://splunk-base.splunk.com/answers/28869/my-username-in-the-dashboard"&gt;http://splunk-base.splunk.com/answers/28869/my-username-in-the-dashboard&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks for all the help so far.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Aug 2011 00:42:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61441#M12231</guid>
      <dc:creator>jgauthier</dc:creator>
      <dc:date>2011-08-21T00:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61442#M12232</link>
      <description>&lt;P&gt;This is not a full fledged answer, but it will be too long for a comment.&lt;BR /&gt;
I was able to get the username, when I thought about my original question.  I can do this like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; $.ajax({
    url: '/en-US/app/launcher/home', 
    type: 'GET', 
    success: function(msg){
    var messenger = Splunk.Messenger.System.getInstance();
        var start=msg.indexOf(" ", logged+12)+1;
        var end=msg.indexOf(String.fromCharCode(13), start);
        var username=msg.substring(start,end);
        // I have the username.. now what?
    }
 });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is exciting.  But now what?  How can I expose this in a dashboard? Can the XML call a js function? Or otherwise make a variable accessible? Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2011 15:22:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61442#M12232</guid>
      <dc:creator>jgauthier</dc:creator>
      <dc:date>2011-08-22T15:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61443#M12233</link>
      <description>&lt;P&gt;Technically, this should probably be a new question.  In any case, user and session information are not exposed to JavaScript.  Rather, they are exposed via the cherrypy session object - see &lt;A href="http://dev.splunk.com/view/SP-CAAADS2#controller_show"&gt;http://dev.splunk.com/view/SP-CAAADS2#controller_show&lt;/A&gt;.  Can you explain why you need the user name via JavaScript?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2011 18:25:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61443#M12233</guid>
      <dc:creator>araitz</dc:creator>
      <dc:date>2011-08-22T18:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61444#M12234</link>
      <description>&lt;P&gt;Use /en-US/api/search/jobs to access jobs via the Splunk Web port (just as Splunk Web does), or even better, just use the built in search, jobs, and time_range JS objects that we expose.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2011 18:27:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61444#M12234</guid>
      <dc:creator>araitz</dc:creator>
      <dc:date>2011-08-22T18:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61445#M12235</link>
      <description>&lt;P&gt;Ultimately, I want to use the username in dashboards. It doesn't have to be javascript, but I can't figure out any other way to obtain that from a dashboard.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2011 19:19:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61445#M12235</guid>
      <dc:creator>jgauthier</dc:creator>
      <dc:date>2011-08-22T19:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: REST and javascript not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61446#M12236</link>
      <description>&lt;P&gt;Understood.  The easiest way is to access cherrypy.session['user']['name'] via Python, either in a Mako Template or via a Controller.  Since you want to display the user name, I would recommend a template.  See ./splunk/share/splunk/search_mrsparkle/modules/nav/AccountBar.html for a good example.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2011 22:13:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-and-javascript-not-working/m-p/61446#M12236</guid>
      <dc:creator>araitz</dc:creator>
      <dc:date>2011-08-22T22:13:36Z</dc:date>
    </item>
  </channel>
</rss>

