- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SDK javascript: client side test (error 404)
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,
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm running into the same problem when I run the sample from Visual Studio. Do you have any idea where shall I add similar settings when it comes to IIS?
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
