我正在尝试从 Splunk 中获取一些信息,以便我可以使用它。我登录成功,但是我什么也做不了。我试图让我保存的搜索和工作无济于事。这是我用来登录并尝试获取保存的搜索的代码。
var splunkjs = require('splunk-sdk');
var service = new splunkjs.Service({username: "****", password: "*****", host: "dllprdspl01.dl.prd.p.******.com", port: 8089, scheme: "https", version: 5});
service.login(function(err, success) {
if (err) {
throw err;
}
console.log("Login was successful: " + success);
var mySavedSearches = service.savedSearches();
mySavedSearches.fetch(function(err, mySavedSearches) {
console.log("There are " + mySavedSearches.list().length + " saved searches");
var savedSearchColl = mySavedSearches.list();
for(var i = 0; i < savedSearchColl.length; i++) {
var search = savedSearchColl[i];
console.log(i + ": " + savedSearchColl[i].name);
console.log(" Query: " + savedSearchColl[i].properties().search + "\n");
}
});
});
我在登录时成功返回,但是当我尝试列出我保存的搜索时,我收到此错误:
TypeError: Cannot call method 'list' of undefined
登录后,我已将我的服务打印到控制台,但我没有看到任何看起来有问题的地方。
我已经能够使用以下代码连接并获取会话密钥:
var splunkjs = require('splunk-sdk');
var xml2js = require('xml2js');
var context = new splunkjs.Context({username: "****", password: "****", host: "****.com", port: 8089, scheme: "https", version: 5});
var sessionKey;
var key = context.login(function(err, success){
if(err){
throw err;
}
// console.log("Login was successful " + success);
var keyXml = key.req.res.body;
var parser = new xml2js.Parser();
parser.parseString(keyXml, function(err, result){
sessionKey = result.response.sessionKey[0];
});
context.sessionKey = sessionKey;
console.log(context);
context.get('services/saved/searches/hamm_test_mn7', function(err, response){
console.get(response);
})
});
如果我能得到我的会话密钥,那么我应该登录到 splunk。我将如何从那里完成我保存的搜索。