Skip to content

SDK Support for splunkd search API changes #157

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 17 commits into from
Jun 16, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- 14
- 8.17.0
splunk-version:
- "8.0"
- "8.2"
- "latest"

services:
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*build/
build/
.git
tests/html/*
*.out
Expand All @@ -17,4 +17,5 @@ cover_html
.splunkrc
*.zip
test_logs/*
docs/
docs/
.nyc_output/*
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@ wait_up:
down:
@echo "$(ATTN_COLOR)==> down $(NO_COLOR)"
@docker-compose stop

.PHONY: deps
deps:
@echo "$(ATTN_COLOR)==> Checking nodes.js dependencies $(NO_COLOR)"
@echo "$(ATTN_COLOR)==> Installing nodes.js 14 $(NO_COLOR)"
@source $(HOME)/.nvm/nvm.sh ; nvm install 14
@echo "$(ATTN_COLOR)==> npm install $(NO_COLOR)"
@npm install

.PHONY: clean
clean:
@echo "$(ATTN_COLOR)==> Cleaning client/ directory $(NO_COLOR)"
@rm -rf client/splunk.*.js >/dev/null 2>&1

.PHONY: build
build: clean deps
@echo "$(OK_COLOR)==> Initiating the build... $(NO_COLOR)"
@source $(HOME)/.nvm/nvm.sh; nvm run 14 sdkdo compile
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ For more information, see [Splunk Enterprise SDK for JavaScript](https://dev.spl

The Splunk Enterprise SDK for JavaScript was tested with Node.js v8.17.0, v14.

* Splunk Enterprise 8.0 or 8.2, or Splunk Cloud
* Splunk Enterprise 9.0 or 8.2, or Splunk Cloud

The Splunk Enterprise SDK for JavaScript was tested with Splunk Enterprise 8.0 or 8.2, or Splunk Cloud.
The Splunk Enterprise SDK for JavaScript was tested with Splunk Enterprise 9.0 or 8.2, or Splunk Cloud.

* Splunk Enterprise SDK for JavaScript

Expand Down Expand Up @@ -124,7 +124,7 @@ var serviceWithSessionKey = new splunkjs.Service(
host: 'localhost',
port: '8089',
sessionKey: SESSION_KEY, // Add your sessionKey here
version: '8',
version: '9.0',
});

serviceWithSessionKey.get("search/jobs", { count: 1 }, function (err, res) {
Expand Down Expand Up @@ -204,7 +204,7 @@ To use this convenience file, create a text file with the following format:
# Access scheme (default: https)
scheme=https
# Your version of Splunk Enterprise
version=8.2
version=9.0

Save the file as **.splunkrc** in the current user's home directory.

Expand Down
28 changes: 14 additions & 14 deletions client/browser_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Context tests', function() {
})
describe('General Context Test', function() {
before(function(){
console.log(svc);
// console.log(svc);
this.service = svc;
})

Expand Down Expand Up @@ -152,9 +152,11 @@ describe('Context tests', function() {
}
);

service.get("search/jobs", {count: 1}, function(err, res) {
assert.ok(err);
assert.strictEqual(err.status, 401);
service.get("search/jobs", { count: 1 }, function (err, res) {
assert.strictEqual(res.data.paging.offset, 0);
assert.ok(res.data.entry.length <= res.data.paging.total);
assert.strictEqual(res.data.entry.length, 1);
assert.ok(res.data.entry[0].content.sid);
done();
});
});
Expand Down Expand Up @@ -282,9 +284,9 @@ describe('Context tests', function() {
}
);

service.post("search/jobs", {search: "search index=_internal | head 1"}, function(err, res) {
assert.ok(err);
assert.strictEqual(err.status, 401);
service.post("search/jobs", { search: "search index=_internal | head 1" }, function (err, res) {
var sid = res.data.sid;
assert.ok(sid);
done();
});
});
Expand Down Expand Up @@ -412,9 +414,9 @@ describe('Context tests', function() {
}
);

service.del("search/jobs/NO_SUCH_SID", {}, function(err, res) {
service.del("search/jobs/NO_SUCH_SID", {}, function (err, res) {
assert.ok(err);
assert.strictEqual(err.status, 401);
assert.strictEqual(err.status, 404);
done();
});
});
Expand Down Expand Up @@ -579,9 +581,8 @@ describe('Context tests', function() {
var get = {count: 1};
var post = null;
var body = null;
service.request("search/jobs", "GET", get, post, body, {"X-TestHeader": 1}, function(err, res) {
assert.ok(err);
assert.strictEqual(err.status, 401);
service.request("search/jobs", "GET", get, post, body, { "X-TestHeader": 1 }, function (err, res) {
assert.ok(res);
done();
});
});
Expand Down Expand Up @@ -799,7 +800,6 @@ describe('Context tests', function() {
that.skip = true;
splunkjs.Logger.log("Skipping cookie tests...");
}
done();
});
})

Expand Down Expand Up @@ -827,7 +827,7 @@ describe('Context tests', function() {
done();
});

it("login and store cookie", function(done){
it("login and store cookie", function (done) {
if(this.skip){
done();
return;
Expand Down
75 changes: 75 additions & 0 deletions client/browser_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,82 @@ describe("Service Tests ", function(){
}
);
});

it("Callback#job events - fallback to v1 with search params", function(done) {
var sid = getNextId();
var service = this.service;
var that = this;

Async.chain([
function(done) {
that.service.jobs().search('search index=_internal | head 2', {id: sid}, done);
},
function(job, done) {
assert.strictEqual(job.sid, sid);
pollUntil(
job,
function(j) {
return job.properties()["isDone"];
},
10,
done
);
},
function(job, done) {
job.events({search: "| head 1"}, done);
},
function (results, job, done) {
assert.strictEqual(results.post_process_count, 1);
assert.notEqual(job._state.links.alternate.indexOf("/search/jobs/"), -1);
assert.strictEqual(results.rows.length, 1);
assert.strictEqual(results.fields.length, results.rows[0].length);
job.cancel(done);
}
],
function(err) {
assert.ok(!err);
done();
}
);
});

it("Callback#job events - use v2 endpoints: no search params", function(done) {
var sid = getNextId();
var service = this.service;
var that = this;

Async.chain([
function(done) {
that.service.jobs().search('search index=_internal | head 2', {id: sid}, done);
},
function(job, done) {
assert.strictEqual(job.sid, sid);
pollUntil(
job,
function(j) {
return job.properties()["isDone"];
},
10,
done
);
},
function(job, done) {
job.events({}, done);
},
function (results, job, done) {
assert.isUndefined(results.post_process_count);
assert.strictEqual(results.rows.length, 2);
assert.strictEqual(results.fields.length, results.rows[0].length);
job.cancel(done);
}
],
function(err) {
assert.ok(!err);
done();
}
);
});

it("Callback#job results preview", function(done) {
var sid = getNextId();
var service = this.service;
Expand Down
Loading