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!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...