Dashboards & Visualizations

Why am I getting a 404 error trying to connect to Splunk Enterprise using the JavaScript SDK?

jameskerivan
Explorer

Hi Guys,

I was building a dashboard for my company and needed to get Splunk information. Right now, I use the JavaScript SDK like this:

$(document).ready(function() {
    $('#searchButton').on('click', displayApps);
});

function displayApps(event) {
        var http = new splunkjs.ProxyHttp("/proxy");

    // Create a Service instance and log in 
    var service = new splunkjs.Service(http, {
        username:"username",
        password:"password",
        scheme:"https",
        host:"hostname.com",
        port:"correctport#",
        version:"5.0"
    });

    // Verify we logged in
    // Print installed apps to the console to verify login
    service.apps().fetch(function(err, apps) {
        if (err) {
            console.log(err);
            return;
        }

        var myapps = "";
        var appsList = apps.list();
        for(var i = 0; i < appsList.length; i++) {
        } 
    }); 

}

The thing is, I am getting a 404 error.

POST http://localhost:3000/proxy/services/auth/login?output_mode=json 404 (Not Found)  jquery.min.js:4 

Object {response: Object, status: 404, data: "<!DOCTYPE html><html><head><title></title><link re…ss\lib\router\index.js:46:12)</pre></body></html>", error: "Not Found"}  splunkSession.js:23

I apologize as I am new to web dev, so I am trying to hack this together as best as I can.

Thanks again

0 Karma

frobinson_splun
Splunk Employee
Splunk Employee

Hi @jameskerivan,
I'm not sure of all the details of your situation, but did you make sure to start splunkd (Splunk server) before running this code?
See this resource in our documentation:
http://dev.splunk.com/view/javascript-sdk/SP-CAAAEC9

I hope this helps! If not, we can continue troubleshooting.
Best,
@frobinson_splunk

0 Karma

jameskerivan
Explorer

My company has the splunk server running at the hostname. I have double checked the hostname and port#. My credentials allow me to login through the UI so I assume they are correct. I have tried different schemes, but nothing so far.

0 Karma

frobinson_splun
Splunk Employee
Splunk Employee

Ok, on taking a look for other answers posts that seem related, it sounds like double-checking the server configurations regarding the proxy might be helpful. See these previous posts:
http://answers.splunk.com/answers/71756/starting-with-javascript-sdk.html

http://answers.splunk.com/answers/55188/sdk-javascript-client-side-test-error-404.html

Again, let me know if this does not help. Other folks might chime in here too 🙂

All best,
@frobinson_splunk

0 Karma
Get Updates on the Splunk Community!

Build Scalable Security While Moving to Cloud - Guide From Clayton Homes

 Clayton Homes faced the increased challenge of strengthening their security posture as they went through ...

Mission Control | Explore the latest release of Splunk Mission Control (2.3)

We’re happy to announce the release of Mission Control 2.3 which includes several new and exciting features ...

Cloud Platform | Migrating your Splunk Cloud deployment to Python 3.7

Python 2.7, the last release of Python 2, reached End of Life back on January 1, 2020. As part of our larger ...