我正在尝试使用 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 错误。我还需要检查什么以查看我做错了什么。