Skip to content

Commit 721a9ff

Browse files
authored
Merge pull request #157 from splunk/DVPL-10898-develop
SDK Support for splunkd search API changes
2 parents 37cb4ec + 5f1df1d commit 721a9ff

File tree

17 files changed

+13275
-12468
lines changed

17 files changed

+13275
-12468
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- 14
1515
- 8.17.0
1616
splunk-version:
17-
- "8.0"
17+
- "8.2"
1818
- "latest"
1919

2020
services:

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*build/
1+
build/
22
.git
33
tests/html/*
44
*.out
@@ -17,4 +17,5 @@ cover_html
1717
.splunkrc
1818
*.zip
1919
test_logs/*
20-
docs/
20+
docs/
21+
.nyc_output/*

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ wait_up:
4545
down:
4646
@echo "$(ATTN_COLOR)==> down $(NO_COLOR)"
4747
@docker-compose stop
48+
49+
.PHONY: deps
50+
deps:
51+
@echo "$(ATTN_COLOR)==> Checking nodes.js dependencies $(NO_COLOR)"
52+
@echo "$(ATTN_COLOR)==> Installing nodes.js 14 $(NO_COLOR)"
53+
@source $(HOME)/.nvm/nvm.sh ; nvm install 14
54+
@echo "$(ATTN_COLOR)==> npm install $(NO_COLOR)"
55+
@npm install
56+
57+
.PHONY: clean
58+
clean:
59+
@echo "$(ATTN_COLOR)==> Cleaning client/ directory $(NO_COLOR)"
60+
@rm -rf client/splunk.*.js >/dev/null 2>&1
61+
62+
.PHONY: build
63+
build: clean deps
64+
@echo "$(OK_COLOR)==> Initiating the build... $(NO_COLOR)"
65+
@source $(HOME)/.nvm/nvm.sh; nvm run 14 sdkdo compile

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ For more information, see [Splunk Enterprise SDK for JavaScript](https://dev.spl
1313

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

16-
* Splunk Enterprise 8.0 or 8.2, or Splunk Cloud
16+
* Splunk Enterprise 9.0 or 8.2, or Splunk Cloud
1717

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

2020
* Splunk Enterprise SDK for JavaScript
2121

@@ -124,7 +124,7 @@ var serviceWithSessionKey = new splunkjs.Service(
124124
host: 'localhost',
125125
port: '8089',
126126
sessionKey: SESSION_KEY, // Add your sessionKey here
127-
version: '8',
127+
version: '9.0',
128128
});
129129

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

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

client/browser_context.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Context tests', function() {
2525
})
2626
describe('General Context Test', function() {
2727
before(function(){
28-
console.log(svc);
28+
// console.log(svc);
2929
this.service = svc;
3030
})
3131

@@ -152,9 +152,11 @@ describe('Context tests', function() {
152152
}
153153
);
154154

155-
service.get("search/jobs", {count: 1}, function(err, res) {
156-
assert.ok(err);
157-
assert.strictEqual(err.status, 401);
155+
service.get("search/jobs", { count: 1 }, function (err, res) {
156+
assert.strictEqual(res.data.paging.offset, 0);
157+
assert.ok(res.data.entry.length <= res.data.paging.total);
158+
assert.strictEqual(res.data.entry.length, 1);
159+
assert.ok(res.data.entry[0].content.sid);
158160
done();
159161
});
160162
});
@@ -282,9 +284,9 @@ describe('Context tests', function() {
282284
}
283285
);
284286

285-
service.post("search/jobs", {search: "search index=_internal | head 1"}, function(err, res) {
286-
assert.ok(err);
287-
assert.strictEqual(err.status, 401);
287+
service.post("search/jobs", { search: "search index=_internal | head 1" }, function (err, res) {
288+
var sid = res.data.sid;
289+
assert.ok(sid);
288290
done();
289291
});
290292
});
@@ -412,9 +414,9 @@ describe('Context tests', function() {
412414
}
413415
);
414416

415-
service.del("search/jobs/NO_SUCH_SID", {}, function(err, res) {
417+
service.del("search/jobs/NO_SUCH_SID", {}, function (err, res) {
416418
assert.ok(err);
417-
assert.strictEqual(err.status, 401);
419+
assert.strictEqual(err.status, 404);
418420
done();
419421
});
420422
});
@@ -579,9 +581,8 @@ describe('Context tests', function() {
579581
var get = {count: 1};
580582
var post = null;
581583
var body = null;
582-
service.request("search/jobs", "GET", get, post, body, {"X-TestHeader": 1}, function(err, res) {
583-
assert.ok(err);
584-
assert.strictEqual(err.status, 401);
584+
service.request("search/jobs", "GET", get, post, body, { "X-TestHeader": 1 }, function (err, res) {
585+
assert.ok(res);
585586
done();
586587
});
587588
});
@@ -799,7 +800,6 @@ describe('Context tests', function() {
799800
that.skip = true;
800801
splunkjs.Logger.log("Skipping cookie tests...");
801802
}
802-
done();
803803
});
804804
})
805805

@@ -827,7 +827,7 @@ describe('Context tests', function() {
827827
done();
828828
});
829829

830-
it("login and store cookie", function(done){
830+
it("login and store cookie", function (done) {
831831
if(this.skip){
832832
done();
833833
return;

client/browser_service.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,82 @@ describe("Service Tests ", function(){
452452
}
453453
);
454454
});
455+
456+
it("Callback#job events - fallback to v1 with search params", function(done) {
457+
var sid = getNextId();
458+
var service = this.service;
459+
var that = this;
460+
461+
Async.chain([
462+
function(done) {
463+
that.service.jobs().search('search index=_internal | head 2', {id: sid}, done);
464+
},
465+
function(job, done) {
466+
assert.strictEqual(job.sid, sid);
467+
pollUntil(
468+
job,
469+
function(j) {
470+
return job.properties()["isDone"];
471+
},
472+
10,
473+
done
474+
);
475+
},
476+
function(job, done) {
477+
job.events({search: "| head 1"}, done);
478+
},
479+
function (results, job, done) {
480+
assert.strictEqual(results.post_process_count, 1);
481+
assert.notEqual(job._state.links.alternate.indexOf("/search/jobs/"), -1);
482+
assert.strictEqual(results.rows.length, 1);
483+
assert.strictEqual(results.fields.length, results.rows[0].length);
484+
job.cancel(done);
485+
}
486+
],
487+
function(err) {
488+
assert.ok(!err);
489+
done();
490+
}
491+
);
492+
});
493+
494+
it("Callback#job events - use v2 endpoints: no search params", function(done) {
495+
var sid = getNextId();
496+
var service = this.service;
497+
var that = this;
455498

499+
Async.chain([
500+
function(done) {
501+
that.service.jobs().search('search index=_internal | head 2', {id: sid}, done);
502+
},
503+
function(job, done) {
504+
assert.strictEqual(job.sid, sid);
505+
pollUntil(
506+
job,
507+
function(j) {
508+
return job.properties()["isDone"];
509+
},
510+
10,
511+
done
512+
);
513+
},
514+
function(job, done) {
515+
job.events({}, done);
516+
},
517+
function (results, job, done) {
518+
assert.isUndefined(results.post_process_count);
519+
assert.strictEqual(results.rows.length, 2);
520+
assert.strictEqual(results.fields.length, results.rows[0].length);
521+
job.cancel(done);
522+
}
523+
],
524+
function(err) {
525+
assert.ok(!err);
526+
done();
527+
}
528+
);
529+
});
530+
456531
it("Callback#job results preview", function(done) {
457532
var sid = getNextId();
458533
var service = this.service;

0 commit comments

Comments
 (0)