Currently, I am attempting to establish a connection to Splunk using JavaScript. While I have successfully connected using Java and have full functionality, I keep encountering a 401 error when trying to connect with JavaScript. I am certain that my credentials are correct since they work for Java. The JavaScript code I'm using is taken directly from the examples available. Here's the snippet:
exports.main = function(opts, done) {
// Testing purposes only - please disregard
opts = opts || {};
var username = opts.username || "username";
var password = opts.password || "password";
var scheme = opts.scheme || "https";
var host = opts.host || "domain.com";
var port = opts.port || "8089";
var version = opts.version || "5";
var service = new splunkjs.Service({
username: "username",
password: "password",
scheme: "https",
host: "domain.com",
port: "8089",
version: "5"
});
// Logging in first
service.login(function(err, success) {
if (err || !success) {
console.log("Error in logging in");
console.log(err);
done(err || "Login failed");
return;
}
// Once logged in, let's retrieve a list of saved searches
service.savedSearches().fetch(function(err, searches) {
if (err) {
console.log("There was an error retrieving the list of saved searches:", err);
done(err);
return;
}
var searchList = searches.list();
console.log("Saved searches:");
for(var i = 0; i < searchList.length; i++) {
var search = searchList[i];
console.log(" Search " + i + ": " + search.name);
console.log(" " + search.properties().search);
}
done();
});
});
};
if (module === require.main) {
exports.main({}, function() {});
}
Below is the specific error message received:
There was an error retrieving the list of saved searches: { response:
{ headers:
{ connection: 'close',
'content-length': '100',
'content-type': 'text/xml; charset=utf-8',
date: 'Tue, 20 Nov 2012 22:27:11 GMT',
server: 'Splunkd' },
statusCode: 401 },
status: 401,
data: '<response>\n<messages>\n<msg type="WARN">call not properly authenticated</msg>\n</messages>\n</response>',
error: null }
Executing this on the command line using Node results in the 401 error. I'm unsure what else I should investigate to pinpoint where I might be going wrong.