Refine your search:

Hello,

I try to use sdk javascript client side so I've splunk on my host where I add the app JSON2 and I have my project on eclipse where I copy the folder client and jquery.min.js. I want to connect to my local splunk so I have test this:

<html>
  <head>
    <meta charset="utf-8">
    <title>How to start a Splunk session</title>
    <script type="text/javascript" src="scripts/jquery.min.js"></script>
    <script type="text/javascript" src="scripts/client/splunk.js"></script>

    <script type="text/javascript" charset="utf-8">
    function displayApps() {
        var http = new splunkjs.ProxyHttp("/proxy");

        // Create a Service instance and log in 
        var service = new splunkjs.Service(http, {
            username: "admin",
            password: "admin",
            scheme: "https",
            host: "localhost",
            port: "8089"
        });
        // Print installed apps to the console to verify login
        service.apps().fetch(function(err, apps) {
            if (err) {
                alert("Error listing apps");
                return;
            }

            var myapps = "";
            var appsList = apps.list();
            for(var i = 0; i < appsList.length; i++) {
                myapps += "App " + i + ": " + appsList[i].name + "<br/>"
            }

            document.getElementById("applist").innerHTML=myapps;
        });

    }
    </script> 
</head>
<body>
    <button type="button" onclick="displayApps()">Log in and list apps</button>
    <p id="applist"></p>
</body>
</html>

But I've the alert "Error listing apps" and the error is :

"NetworkError: 404 Introuvable - http://localhost:8080/proxy/services/json/v2/services/auth/login?"
login?
POST http://localhost:8080/proxy/services/json/v2/services/auth/login?  
404 Introuvable

And it's say that it's in jquery.min.js that there is the error and I do'nt know why is localhost:8080 and not 8089?????

Thx by advance if you know where is come from the error.

Laura,

asked 07 Aug '12, 05:17

LauraBre's gravatar image

LauraBre
151238
accept rate: 14%

edited 11 Aug '12, 10:52

hexx's gravatar image

hexx ♦
13.6k91568


One Answer:

The problem you're having is due to the browser's Single Origin Policy (http://en.wikipedia.org/wiki/Same_origin_policy). The specific issue is that your page is going to be running of yourawesomedomain.com, but Splunk will be running on some separate domain (e.g. yourawesomedomain.com:8089), and the browser does not allow communication to happen between those two.

The solution is to use a server-side proxy to relay the messages. For example, when you run the examples in the SDK, we start up a small webserver that proxies any request to the the "/proxy" endpoint to Splunk. You can similarly have a small proxy in your webserver that does the same.

If you can say a bit more about your environment (what programming language you're using server side, what webserver, etc), I can give a bit more specific advice and help.

link

answered 07 Aug '12, 12:07

ineeman's gravatar image

ineeman
49822
accept rate: 31%

Hello,

Thanks very much for your answer. So, if I understand, I have to add a proxy in my apache (I work with a tomcat apache) and eclipse. I program in java. So I create a proxy of my choice. Then what have I to change in my dynamic web java project? And next I just to add the proxy in my browser?

Thx by advance,

Laura

(08 Aug '12, 08:46) LauraBre
2

You can try adding the following two lines to your Apache config file:

SSLProxyEngine On ProxyPass /proxy/ https://localhost:4089/

You will need to change localhost:4089 to wherever your splunkd is (the management host and port). Once you do that, any request that goes to /proxy on your server will be routed to your splunkd installation.

(10 Aug '12, 10:54) ineeman

Thx, I did it. I insert my index.html in htdocs of my apache and I add SSLProxyEngine On ProxyPass /proxy/ https://localhost:8089/ in the Apache config file and decommented all modules about proxy. So it works cery well when I doen't use tomcat but when I use tomcat and Apache, there is the error 404 so I don't result the problem with tomcat but I can connect to my spolunk so it's a good thing. Now I want to use this in a dynamic web project where I use tomcat so I search I can I do it? Do you have an idea?

Thx by advance,

Laura

(13 Aug '12, 08:29) LauraBre
Post your answer
toggle preview

Follow this question

Log In to enable email subscriptions

RSS:

Answers

Answers + Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×82
×51
×19

Asked: 07 Aug '12, 05:17

Seen: 863 times

Last updated: 13 Aug '12, 08:29

Copyright © 2005-2012 Splunk Inc. All rights reserved.