Javascript を使用して Splunk に接続しようとしています。私はすでにJavaに接続しており、私がやりたいことは何でもできます。Javascript に接続しようとすると、401 が返されます。Java と Javascript の両方に同じ資格情報を使用しているため、問題がないことがわかっています。私のコードは例から直接出ています。ここにあります:
exports.main = function(opts, done) {
// This is just for testing - ignore it
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"
});
// First, we log in
service.login(function(err, success) {
// We check for both errors in the connection as well
// as if the login itself failed.
if (err || !success) {
console.log("Error in logging in");
console.log(err);
done(err || "Login failed");
return;
}
// Now that we're logged in, let's get a listing of all the 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() {});
}
エラーメッセージは次のとおりです。
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 }
Node を使用してコマンド ラインでこれを実行すると、401 エラーが発生します。私が間違っていることを確認するために、他に何を確認する必要がありますか。