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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...