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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...