Also versuche ich, die splunk-sdk-Bibliothek zu promitieren, aber es scheint, als ob ich nicht verstehe, wie Promistification funktioniert, zumindest mit Coroutinen.Probleme haben, die obskure Bibliothek zu promoten und sie dann in einer Coroutine zu verwenden
HINWEIS: Ich verwende bluebirdjs
Hier ist der Prozess, den ich in einem Koroutine nachzubilden versucht habe:
// Search everything and return the first 100 results
var searchQuery = "search * | head 100";
// Set the search parameters
var searchParams = {
exec_mode: "blocking",
earliest_time: "2012-06-20T16:27:43.000-07:00"
};
// A blocking search returns the job's SID when the search is done
console.log("Wait for the search to finish...");
// Run a blocking search and get back a job
service.search(
searchQuery,
searchParams,
function(err, job) {
console.log("...done!\n");
// Get the job from the server to display more info
job.fetch(function(err){
// Display properties of the job
console.log("Search job properties\n---------------------");
console.log("Search job ID: " + job.sid);
console.log("The number of events: " + job.properties().eventCount);
console.log("The number of results: " + job.properties().resultCount);
console.log("Search duration: " + job.properties().runDuration + " seconds");
console.log("This job expires in: " + job.properties().ttl + " seconds");
// Get the results and display them
job.results({}, function(err, results) {
var fields = results.fields;
var rows = results.rows;
for(var i = 0; i < rows.length; i++) {
var values = rows[i];
console.log("Row " + i + ": ");
for(var j = 0; j < values.length; j++) {
var field = fields[j];
var value = values[j];
console.log(" " + field + ": " + value);
}
}
})
});
}
);
Sein von this Tutorial
Dies ist, was meine Bemühungen haben ergab (Pun teilweise beabsichtigt?)
"use strict";
//Get the splunk sdk
var splunkjs = require('splunk-sdk');
//get promise dependencies
Promise = require("bluebird");
//get request dependencies
var request = require('request-promise');
//Promisify dependencies
splunkjs = Promise.promisifyAll(splunkjs);
//create a promise generator
exports.splunkTest = Promise.coroutine(function*(){
try{
// Create a Service instance and log in
let service = yield Promise.promisifyAll(Promise.resolve(new splunkjs.Service({
username:"user",
password:"password",
scheme:"https",
host:"host",
port:"8089",
version:"6.3.2"
})));
// Pass the search query
let searchQuery = "search * | head 100";
let searchParams = {
exec_mode: "blocking"
};
let job = yield Promise.resolve(service.search(searchQuery,searchParams,function(err,job){return console.log("running");return job;}));
//JOB DOESN'T CONTAIN FUNCTIONS!!! :(
return yield Promise.resolve(job);
} catch (e){
console.log(e)
}
});
Das Auftragsobjekt hat in meinem, wahrscheinlich fehlerhaften, Versuch, den Prozess in eine Coroutine umzuwandeln, keine Funktion.
Kann jemand eine allgemeine Anleitung anbieten?