Splunk Dev

Not able to connect to splunk using javascript sdk

kavyatim
Path Finder

I installed node.js ,copied xmljson to splunk app.
Done with everything as per the document.
The client side program is as follows:




How to start a Splunk session

<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:"kav$tim1",
        scheme:"http",
        host:"localhost",
        port:"8089",
        version:"5.0"
    });

   // Verify we logged in


 // First, we log in

service.login(function(err, success) {
// We check for both errors in the connection as well
// as if the login itself failed.
if (err || !success) {
console.log("Error in logging in");
done(err || "Login failed");
return;
}

    // Print installed apps to the console to verify login
    service.apps().fetch(function(err, apps) {
        if (err) {
       console.log("There was an error retrieving the list of applications:", err);
        done(err);
        return;
        }

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

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

}
</script> 






Tags (1)

jitendra0101
Engager

Please help. Every time I am getting error message as "There was an error retrieving the list of applications".

0 Karma

guilhem
Contributor

I have made another question as there is not enough room in the comment. See
http://splunk-base.splunk.com/answers/84184/javascript-sdk-internal-server-error

0 Karma

Neeraj_Luthra
Splunk Employee
Splunk Employee

@guilhem - What error are you running into? Assuming that you are using node v0.8.x.

0 Karma

guilhem
Contributor

Did you solve this problem? I have exactly the same error as you describe and would be interested in a solution.

By the way you need to use node v0.8.x (and not the latest release) as otherwise it will not work. see http://splunk-base.splunk.com/answers/79378/splunk-502-javascript-sdk-server-error-500-examples-brow...

0 Karma

Neeraj_Luthra
Splunk Employee
Splunk Employee

There are a few issues with what you are doing:

  1. If you are on Splunk 5, you do not need xml2json, unless of course you are trying to run the unit tests.
  2. service.login function call is missing a couple of closing parenthesis.
  3. scheme should be https, unless you have changed the default Splunk installation.
  4. You need to serve this page from a web server and in that web server you will need to set up the proxy. This last steps is taken care of if you run the examples through node, i.e. node sdkdo examples from the command line. This is also documented at JavaScript SDK Browser Examples.
0 Karma
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...