Splunk Dev

Can´t connect to splunk

splunkjunkxx
New Member

Hi guys

When i run following code

   <html>
  <head>
    <meta charset="utf-8">
    <title>How to start a Splunk session</title>
    <!--<script type="text/javascript" src="/static/app/kaisers_weinberater/jquery.min.js"></script>-->
    <script type="text/javascript" src="/static/app/kaisers_weinberater/splunk-sdk-javascript/client/splunk.js"></script>

    <script type="text/javascript" charset="utf-8">
    function displayApps() {
        var http = new splunkjs.ProxyHttp("/proxy");

        // Create a Service instance and log in 
        var service = new splunkjs.Service(http, {
            username: "admin",
            password: "admin",
            scheme: "https",
            host: "localhost",
            port:"8089",
            version:"5.0.1"
        }); 

// Retrieve the collection of jobs
var myJobs = service.jobs();

myJobs.fetch(function(err, jobs) {

  // Determine how many jobs are in the collection
  var jobsList = myJobs.list() || [];
  console.log("There are " + jobsList.length + " jobs available to the current user");

  // Loop through the collection and display each job's SID
  for(var i = 0; i < jobsList.length; i++) {
    console.log((i + 1) + ": " + jobsList[i].sid);
  };
});

    }
    </script> 
</head>
<body>
    <button type="button" onclick="displayApps()">Log in and list apps</button>
    <p id="applist"></p>
</body>
</html>

i get following error:

https://localhost:8000/en-US/proxy/services/auth/login?output_mode=json

Any ideas? Thanks a lot for your help!:)

0 Karma

Neeraj_Luthra
Splunk Employee
Splunk Employee

The 404 seems to be related to the fact that the request isn't actually making it to Splunk. By default, browsers don't allow cross-site scripting - Same origin policy. You will need to tell your web server to proxy specific requests to Splunk. For example, when running apache, following 2 lines of code do the trick.

SSLProxyEngine On
ProxyPass   /proxy/             https://localhost:8089/

Hope this helps.

0 Karma

sinnixx
Explorer

Hi Iguinn:) that´s right. Thought :8089 is the port for communication with the splunk server? How can i instantiate the http object without the proxy function?
After changing this line to var http = new splunkjs.ProxyHttp(".."); i get rid off the 404 error. But the response json data from splunkd is {"data": null, "total": 0, "messages": [{"message": "Invalid viewstate param name: username; aborting", "time": "2013-01-28T09:59:48", "type": "ERROR"}

0 Karma

lguinn2
Legend

I assume that you are running Splunk on the local machine, and that you are using port 8000 (the default)?

0 Karma

splunkjunkxx
New Member
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Automated Threat Analysis: Available in ES Premier

Automated Threat Analysis: Centralize and Accelerate Phishing Investigations in Splunk Enterprise ...

What’s New in Splunk AI: Volume 02

Welcome to the second edition of “What’s New in Splunk AI” where we look at the latest and greatest updates, ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...