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’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...