Splunk Dev

Not able to run splunk javascript sdk examples.

asingla
Communicator

Setup everything as per the docs, changed the user name and password but when click on Run button on the first example, it says "Error in logging in".

When checked developer console, it resulted in this error page

The path '/en-US/services/json/v2/services/auth/login' was not found.

We have "Splunk 4.3 build 115073." installed.

Please advice how I should make these examples run.

Tags (2)
0 Karma

kavyatim
Path Finder

I am not able to login to splunk using javascript sdk.
I have done everything as per the document .
copied xmljson to splunk apps.
Tried mentioning port as 8000 and 8089.
installed node.
The slient side code 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> 






Give me a suggestion

0 Karma

milkmedia
New Member

Make sure you set the port to the management port (8089 by default) rather than the webport (8000, default) as this was my problem when I got that error.

0 Karma

chennuri
New Member

The javascript sdk examples can only be tested from a webserver. To test them from client, install and use node.js. Try this link "http://dev.splunk.com/view/SP-CAAAEDC"

0 Karma

apruneda_splunk
Splunk Employee
Splunk Employee

The xml2json app is included with the JavaScript SDK, and needs to be copied to your Splunk apps directory. Instructions about setting up this app are here:
http://dev.splunk.com/view/SP-CAAAEFN

asingla
Communicator

Done as advised but still the same error. this is how the
the X-ProxyDestination in the request header looks like
http://:8089/services/json/v2/services/auth/login?

0 Karma

asingla
Communicator

Yes I was trying the wrong port. Thanks for that. But now I am getting 500 Internal Server Error with response as {"code":"ECONNRESET"}. Do I need to install xml2json app on the splunk server? Where do I get that?

0 Karma

ineeman
Splunk Employee
Splunk Employee

A couple of quick questions:

  1. Did you install the xml2json app?
  2. When you gave a port in the examples, did you give it 8089 (or whatever the management port is) or 8000, which is the port you use for the UI? It should be the former.
0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...