Skip to content

Changes for savedsearch history pagination #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1704,22 +1704,29 @@
* @example
*
* var savedSearch = service.savedSearches().item("MySavedSearch");
* savedSearch.history(function(err, jobs, search) {
* savedSearch.history({count: 10}, function(err, jobs, search) {
* for(var i = 0; i < jobs.length; i++) {
* console.log("Job", i, ":", jobs[i].sid);
* }
* });
*
* @param {Object} options Options for retrieving history. For a full list, see the <a href="https://docs.splunk.com/Documentation/Splunk/8.0.2/RESTREF/RESTprolog#Pagination_and_filtering_parameters" target="_blank">Pagination and Filtering options</a> in the REST API documentation.
* @param {Function} callback A function to call when the history is retrieved: `(err, job, savedSearch)`.
*
* @endpoint saved/searches/{name}/history
* @method splunkjs.Service.SavedSearch
*/
history: function(callback) {
history: function(options, callback) {
if (!callback && utils.isFunction(options)) {
callback = options;
options = {};
}

callback = callback || function() {};
options = options || {};

var that = this;
return this.get("history", {}, function(err, response) {
return this.get("history", options, function(err, response) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -5675,4 +5682,4 @@
});
}
});
})();
})();
41 changes: 41 additions & 0 deletions tests/service_tests/savedsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,47 @@ exports.setup = function (svc, loggedOutSvc) {
done();
})

it("Callback#history with pagination", function (done) {
var name = "jssdk_savedsearch_" + getNextId();
var originalSearch = "search index=_internal | head 1";
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection" });

Async.chain([
function (done) {
searches.create({ search: originalSearch, name: name }, done);
},
function (search, done) {
assert.ok(search);
search.dispatch(done);
},
function (job, search, done) {
assert.ok(job);
assert.ok(search);
search.dispatch(done);
},
function (job, search, done) {
assert.ok(job);
assert.ok(search);

tutils.pollUntil(
job, () => job.properties()["isDone"], 10, Async.augment(done, search)
);
},
function (job, search, done) {
search.history({ count: 1 }, Async.augment(done, job));
},
function (jobs, search, originalJob, done) {
assert.ok(jobs.length > 0);
assert.equal(jobs.length, 1);
done();
}],
function (err) {
assert.ok(!err);
done();
}
);
});

it("Callback#history error", function (done) {
var name = "jssdk_savedsearch_" + getNextId();
var originalSearch = "search index=_internal | head 1";
Expand Down