splunk-sdk
Advanced tools
Comparing version
# Splunk Enterprise SDK for JavaScript Changelog | ||
## v1.11.0 | ||
### Major changes | ||
* DVPL-9708 apps/local support ([PR#135](https://github.com/splunk/splunk-sdk-javascript/pull/135)) | ||
* .conf CRUD functionality added ([PR#141](https://github.com/splunk/splunk-sdk-javascript/pull/141)) | ||
### Minor changes | ||
* NodeUnit to Mocha Transition for Browser Test Cases ([PR#127](https://github.com/splunk/splunk-sdk-javascript/pull/127)) | ||
* Login example and README.md change ([PR#138](https://github.com/splunk/splunk-sdk-javascript/pull/138)) | ||
* Add pagination support to history calls ([PR#95](https://github.com/splunk/splunk-sdk-javascript/pull/95)) | ||
* Changes for savedsearch history pagination ([PR#139](https://github.com/splunk/splunk-sdk-javascript/pull/139)) | ||
* Add create-react-app browser example ([PR#99](https://github.com/splunk/splunk-sdk-javascript/pull/99)) | ||
* Support added for output_mode for oneShotSearch ([PR#140](https://github.com/splunk/splunk-sdk-javascript/pull/140)) | ||
* Updated Highcharts License. ([PR#119](https://github.com/splunk/splunk-sdk-javascript/pull/119)) | ||
* package-lock.json updated ([PR#137](https://github.com/splunk/splunk-sdk-javascript/pull/137)) | ||
* WIP: Stabilize CI/CD ([PR#115](https://github.com/splunk/splunk-sdk-javascript/pull/115)) | ||
* Dependency updates ([PR#145](https://github.com/splunk/splunk-sdk-javascript/pull/145)) | ||
## v1.10.0 | ||
@@ -4,0 +21,0 @@ |
@@ -20,2 +20,3 @@ # Third-party software credits | ||
| [elementtree](https://github.com/racker/node-elementtree) | Node.js XML parserer and serializer | [Apache-2.0](https://github.com/splunk/splunk-sdk-javascript/blob/master/licenses/LICENSE-ELEMENTTREE) | | ||
| [needle](https://github.com/tomas/needle) | Node.js http client | [MIT](https://github.com/splunk/splunk-sdk-javascript/blob/master/licenses/LICENSE-NEEDLE) | | ||
| [needle](https://github.com/tomas/needle) | Node.js http client | [MIT](https://github.com/splunk/splunk-sdk-javascript/blob/master/licenses/LICENSE-NEEDLE) | | ||
| [Highcharts](https://github.com/highcharts/highcharts) | Interactive JavaScript charts | |
@@ -29,3 +29,3 @@ // Copyright 2014 Splunk, Inc. | ||
// The version number should be updated every time a new version of the JavaScript SDK is released. | ||
var SDK_UA_STRING = "splunk-sdk-javascript/1.10.0"; | ||
var SDK_UA_STRING = "splunk-sdk-javascript/1.11.0"; | ||
@@ -32,0 +32,0 @@ // Create easy to read date format. |
@@ -18,7 +18,12 @@ | ||
var root = exports || this; | ||
var env = require("dotenv").config(); | ||
// Declare a process environment so that we can set | ||
// some globals here and have interop with node | ||
var env = require("dotenv").config(); | ||
process.env = process.env || {}; | ||
try { | ||
process.env = process.env || {}; | ||
} catch (e) { | ||
// Depending on the browser implementation process.env may not | ||
// be assignable but still accessible, ignore these errors | ||
} | ||
@@ -25,0 +30,0 @@ module.exports = root = { |
@@ -359,5 +359,6 @@ /*!*/ | ||
*/ | ||
get: function(path, params, callback) { | ||
get: function(path, params, callback, isAsync) { | ||
var that = this; | ||
var request = function(callback) { | ||
if(isAsync) { | ||
return that.http.get( | ||
@@ -368,7 +369,19 @@ that.urlify(path), | ||
that.timeout, | ||
callback | ||
null, | ||
true | ||
); | ||
}; | ||
return this._requestWrapper(request, callback); | ||
} | ||
else { | ||
var request = function(callback) { | ||
return that.http.get( | ||
that.urlify(path), | ||
that._headers(), | ||
params, | ||
that.timeout, | ||
callback | ||
); | ||
}; | ||
return this._requestWrapper(request, callback); | ||
} | ||
}, | ||
@@ -375,0 +388,0 @@ |
@@ -33,8 +33,2 @@ /*!*/ | ||
// If the output mode doesn't start with "json" (e.g. "csv" or | ||
// "xml"), we change it to "json". | ||
if (!utils.startsWith(outputMode, "json")) { | ||
outputMode = "json"; | ||
} | ||
query.output_mode = outputMode; | ||
@@ -143,3 +137,3 @@ | ||
*/ | ||
get: function(url, headers, params, timeout, callback) { | ||
get: function(url, headers, params, timeout, callback, isAsync) { | ||
var message = { | ||
@@ -152,3 +146,3 @@ method: "GET", | ||
return this.request(url, message, callback); | ||
return this.request(url, message, callback, isAsync); | ||
}, | ||
@@ -214,27 +208,4 @@ | ||
*/ | ||
request: function(url, message, callback) { | ||
request: function(url, message, callback, isAsync) { | ||
var that = this; | ||
var wrappedCallback = function(response) { | ||
callback = callback || function() {}; | ||
// Handle cookies if 'set-cookie' header is in the response | ||
var cookieHeaders = response.response.headers['set-cookie']; | ||
if (cookieHeaders) { | ||
utils.forEach(cookieHeaders, function (cookieHeader) { | ||
var cookie = that._parseCookieHeader(cookieHeader); | ||
that._cookieStore[cookie.key] = cookie.value; | ||
}); | ||
} | ||
// Handle callback | ||
if (response.status < 400 && response.status !== "abort") { | ||
callback(null, response); | ||
} | ||
else { | ||
callback(response); | ||
} | ||
}; | ||
var query = utils.getWithVersion(this.version, queryBuilderMap)(message); | ||
@@ -260,2 +231,3 @@ var post = message.post || {}; | ||
timeout: message.timeout, | ||
query: message.query, | ||
body: body | ||
@@ -266,3 +238,31 @@ }; | ||
// passing in our "wrapped" callback | ||
return this.makeRequest(encodedUrl, options, wrappedCallback); | ||
if(isAsync) { | ||
return this.makeRequestAsync(encodedUrl, options); | ||
} | ||
else { | ||
var wrappedCallback = function(response) { | ||
callback = callback || function() {}; | ||
// Handle cookies if 'set-cookie' header is in the response | ||
var cookieHeaders = response.response.headers['set-cookie']; | ||
if (cookieHeaders) { | ||
utils.forEach(cookieHeaders, function (cookieHeader) { | ||
var cookie = that._parseCookieHeader(cookieHeader); | ||
that._cookieStore[cookie.key] = cookie.value; | ||
}); | ||
} | ||
// Handle callback | ||
if (response.status < 400 && response.status !== "abort") { | ||
callback(null, response); | ||
} | ||
else { | ||
callback(response); | ||
} | ||
}; | ||
return this.makeRequest(encodedUrl, options, wrappedCallback); | ||
} | ||
}, | ||
@@ -269,0 +269,0 @@ |
@@ -44,2 +44,6 @@ | ||
if(message.query && ["xml", "csv"].includes(message.query.output_mode)){ | ||
request_options.parse_response = false; | ||
} | ||
var that = this; | ||
@@ -59,3 +63,11 @@ var req = needle.request(request_options.method, request_options.url, request_options.body, request_options, | ||
var complete_response = that._buildResponse(error, response, JSON.stringify(data)); | ||
var complete_response; | ||
if(message.query && ["xml", "csv"].includes(message.query.output_mode)){ | ||
complete_response = that._buildResponse(error, response, data); | ||
} | ||
else { | ||
complete_response = that._buildResponse(error, response, JSON.stringify(data)); | ||
} | ||
callback(complete_response); | ||
@@ -78,2 +90,24 @@ }); | ||
makeRequestAsync: async function(url, message) { | ||
var request_options = { | ||
url: url, | ||
method: message.method, | ||
headers: message.headers || {}, | ||
body: message.body || "", | ||
timeout: message.timeout || 0, | ||
jar: false, | ||
followAllRedirects: true, | ||
strictSSL: false, | ||
rejectUnauthorized : false, | ||
}; | ||
// Get the byte-length of the content, which adjusts for multi-byte characters | ||
request_options.headers["Content-Length"] = Buffer.byteLength(request_options.body, "utf8"); | ||
var that = this; | ||
var response = needle(request_options.method, request_options.url, request_options.body, request_options); | ||
return response; | ||
}, | ||
parseJson: function(json) { | ||
@@ -80,0 +114,0 @@ return JSON.parse(json); |
{ | ||
"name": "splunk-sdk", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "SDK for usage with the Splunk REST API", | ||
@@ -27,17 +27,17 @@ "homepage": "http://dev.splunk.com", | ||
"dependencies": { | ||
"cookie": "0.4.1", | ||
"dotenv": "^10.0.0", | ||
"cookie": "0.4.2", | ||
"dotenv": "16.0.0", | ||
"elementtree": "0.1.7", | ||
"needle": "2.6.0" | ||
"needle": "3.0.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^17.0.0", | ||
"chai": "^4.3.4", | ||
"jshint": "2.13.0", | ||
"chai": "^4.3.6", | ||
"jshint": "2.13.4", | ||
"mocha": "7.2.0", | ||
"mochawesome": "^6.2.2", | ||
"mochawesome": "7.1.0", | ||
"mustache": "4.2.0", | ||
"nyc": "^15.1.0", | ||
"readable-stream": "3.6.0", | ||
"uglify-js": "3.13.8" | ||
"uglify-js": "3.15.2" | ||
}, | ||
@@ -53,2 +53,2 @@ "author": { | ||
} | ||
} | ||
} |
[](https://travis-ci.org/splunk/splunk-sdk-javascript) | ||
# The Splunk Enterprise Software Development Kit for JavaScript | ||
#### Version 1.10.0 | ||
#### Version 1.11.0 | ||
@@ -92,2 +92,4 @@ The Splunk Enterprise Software Development Kit (SDK) for JavaScript contains library code and examples designed to enable developers to build applications using the Splunk platform and JavaScript. This SDK supports server-side and client-side JavaScript. | ||
##### Login with username and password | ||
```javascript | ||
@@ -111,3 +113,70 @@ var splunkjs = require('splunk-sdk'); | ||
``` | ||
##### Login with sessionKey | ||
```shell | ||
# Create a sessionKey | ||
curl -k -u <username>:<password> <scheme>://<host>:<port>/services/auth/login -d username=<username> -d password=<password> | ||
``` | ||
```javascript | ||
var serviceWithSessionKey = new splunkjs.Service( | ||
{ | ||
// Replace the host if you are accessing remote host | ||
scheme: 'https', | ||
host: 'localhost', | ||
port: '8089', | ||
sessionKey: SESSION_KEY, // Add your sessionKey here | ||
version: '8', | ||
}); | ||
serviceWithSessionKey.get("search/jobs", { count: 1 }, function (err, res) { | ||
if (err) { | ||
console.log(err); | ||
} else } | ||
console.log("Login successful with sessionKey"); | ||
} | ||
}); | ||
``` | ||
##### Login with token | ||
```shell | ||
#### From shell #### | ||
# Enable token authetication | ||
curl -k -u <username>:<password> -X POST <scheme>://<host>:<port>/services/admin/token-auth/tokens_auth -d disabled=false | ||
# Create a token | ||
curl -k -u <username>:<password> -X POST <scheme>://<host>:<port>/services/authorization/tokens?output_mode=json --data name=<username> --data audience=Users --data-urlencode expires_on=+30d | ||
``` | ||
```shell | ||
#### From web #### | ||
# Enable token authentication | ||
Go to settings > Tokens and click on 'Enable Token Authentication' | ||
# Create a token | ||
1. Go to settings > Token and click on 'New Token' | ||
2. Enter the relevant information | ||
3. Copy the created token and save it somewhere safe. | ||
``` | ||
```javascript | ||
var serviceWithBearerToken = new splunkjs.Service( | ||
{ | ||
// Replace the host if you are accessing remote host | ||
scheme: 'https', | ||
host: 'localhost', | ||
port: '8089', | ||
sessionKey: TOKEN, // Add your token here | ||
version: '8', | ||
}); | ||
serviceWithBearerToken.get("search/jobs", { count: 2 }, function (err, res) { | ||
if (err) | ||
console.log(err); | ||
else | ||
console.log("Login successful with bearer token"); | ||
}); | ||
``` | ||
## SDK examples | ||
@@ -155,3 +224,29 @@ | ||
### Create/Update a .conf file | ||
```javascript | ||
Async.chain([ | ||
function (done) { | ||
// Fetch configurations | ||
var configs = svc.configurations(namespace); | ||
configs.fetch(done); | ||
}, | ||
async function (configs, done) { | ||
// Create a key-value map to store under a stanza | ||
const filename = "app.conf"; | ||
const stanzaName = "install"; | ||
var keyValueMap = {} | ||
keyValueMap["state"] = "enabled"; | ||
keyValueMap["python.version"] = "python3"; | ||
// If file/stanza doesn't exist, it will be created | ||
// else it will be updated. | ||
configs.createAsync(filename, stanzaName, keyValueMap, done); | ||
} | ||
], | ||
function (err) { | ||
done(); | ||
}); | ||
``` | ||
### Client-side examples | ||
@@ -158,0 +253,0 @@ |
@@ -142,2 +142,56 @@ var assert = require('chai').assert; | ||
it("Callback#createAsync", function (done) { | ||
var that = this; | ||
var namespace = { owner: "nobody", app: "system" }; | ||
var filename = "jssdk_file_new_" + getNextId(); | ||
var stanza = "install" | ||
var property1 = "state" | ||
var value1 = "enabled"; | ||
var property2 = "python.version" | ||
var value2 = "python3"; | ||
Async.chain([ | ||
function (done) { | ||
var configs = svc.configurations(namespace); | ||
configs.fetch(done); | ||
}, | ||
function (configs, done) { | ||
var keyValueMap = {} | ||
keyValueMap[property1] = value1; | ||
keyValueMap[property2] = value2; | ||
configs.createAsync(filename, stanza, keyValueMap, done); | ||
}, | ||
async function (done) { | ||
var configs = svc.configurations(namespace); | ||
configs.fetch(); | ||
// a. File exists: Positive | ||
var configFile = await configs.getConfFile(filename); | ||
assert.ok(configFile); | ||
// b. Stanza exists: Positive | ||
configFile = await configFile.fetchAsync(); | ||
var configStanza = await configs.getStanza(configFile, stanza); | ||
assert.ok(configStanza); | ||
assert.ok(configStanza._properties); | ||
assert.strictEqual(configStanza._properties[property1], value1 ); | ||
assert.strictEqual(configStanza._properties[property2], value2 ); | ||
// c. File exists: Negative | ||
var invalidConfigFile = await configs.getConfFile("invalid_filename"); | ||
assert.ok(!invalidConfigFile); | ||
// d. Stanza exists: Negative | ||
var invalidConfigStanza = await configs.getStanza(configFile, "invalid_stanza_name"); | ||
assert.ok(!invalidConfigStanza); | ||
done(); | ||
}, | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
}); | ||
}); | ||
it("Callback#can get default stanza", function (done) { | ||
@@ -144,0 +198,0 @@ var that = this; |
@@ -22,35 +22,33 @@ exports.setup = function (svc) { | ||
// Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. | ||
// | ||
// it("Callback#Create+abort job", function (done) { | ||
// var service = this.service; | ||
// Async.chain([ | ||
// function (done) { | ||
// var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdkappcollection/build/sleep_command.tar')); | ||
// // Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) | ||
// app_name = app_name.replace("%20", " "); | ||
// // var app_name = "sleep_command"; | ||
// service.post("apps/local", { update: 1, name: app_name, filename: true }, done); | ||
// }, | ||
// function (done) { | ||
// var sid = getNextId(); | ||
// var options = { id: sid }; | ||
// var jobs = service.jobs(); | ||
// var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function (err, job) { | ||
// assert.ok(err); | ||
// assert.ok(!job); | ||
// assert.strictEqual(err.error, "abort"); | ||
// }); | ||
it("Callback#Create+abort job", function (done) { | ||
var service = this.service; | ||
Async.chain([ | ||
function (done) { | ||
var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdkappcollection/build/sleep_command.tar')); | ||
// Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) | ||
app_name = app_name.replace("%20", " "); | ||
// var app_name = "sleep_command"; | ||
service.post("apps/local", { update: 1, name: app_name, filename: true }, done); | ||
}, | ||
function (done) { | ||
var sid = getNextId(); | ||
var options = { id: sid }; | ||
var jobs = service.jobs(); | ||
var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function (err, job) { | ||
assert.ok(err); | ||
assert.ok(!job); | ||
assert.strictEqual(err.error, "abort"); | ||
}); | ||
// Async.sleep(1000, function () { | ||
// req.abort(); | ||
// }); | ||
// } | ||
// ], | ||
// function (err) { | ||
// assert.ok(!err); | ||
// done(); | ||
// }); | ||
// done(); | ||
// }); | ||
Async.sleep(1000, function () { | ||
req.abort(); | ||
}); | ||
} | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
@@ -279,88 +277,82 @@ it("Callback#Create+cancel job", function (done) { | ||
// Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. | ||
// | ||
// | ||
// it("Callback#Enable + disable preview", function (done) { | ||
// var that = this; | ||
// var sid = getNextId(); | ||
it("Callback#Enable + disable preview", function (done) { | ||
var that = this; | ||
var sid = getNextId(); | ||
// var service = this.service.specialize("nobody", "sdkappcollection"); | ||
var service = this.service.specialize("nobody", "sdkappcollection"); | ||
// Async.chain([ | ||
// function (done) { | ||
// service.jobs().search('search index=_internal | head 1 | sleep 60', { id: sid }, done); | ||
// }, | ||
// function (job, done) { | ||
// job.enablePreview(done); | ||
Async.chain([ | ||
function (done) { | ||
service.jobs().search('search index=_internal | head 1 | sleep 60', { id: sid }, done); | ||
}, | ||
function (job, done) { | ||
job.enablePreview(done); | ||
// }, | ||
// function (job, done) { | ||
// job.disablePreview(done); | ||
// }, | ||
// function (job, done) { | ||
// job.cancel(done); | ||
// } | ||
// ], | ||
// function (err) { | ||
// assert.ok(!err); | ||
// done(); | ||
// } | ||
// ); | ||
// }); | ||
}, | ||
function (job, done) { | ||
job.disablePreview(done); | ||
}, | ||
function (job, done) { | ||
job.cancel(done); | ||
} | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
} | ||
); | ||
}); | ||
// Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. | ||
// | ||
// | ||
// it("Callback#Pause + unpause + finalize preview", function (done) { | ||
// var that = this; | ||
// var sid = getNextId(); | ||
it("Callback#Pause + unpause + finalize preview", function (done) { | ||
var that = this; | ||
var sid = getNextId(); | ||
// var service = this.service.specialize("nobody", "sdkappcollection"); | ||
var service = this.service.specialize("nobody", "sdkappcollection"); | ||
// Async.chain([ | ||
// function (done) { | ||
// service.jobs().search('search index=_internal | head 1 | sleep 5', { id: sid }, done); | ||
// }, | ||
// function (job, done) { | ||
// job.pause(done); | ||
// }, | ||
// function (job, done) { | ||
// tutils.pollUntil( | ||
// job, | ||
// function (j) { | ||
// return j.properties()["isPaused"]; | ||
// }, | ||
// 10, | ||
// done | ||
// ); | ||
// }, | ||
// function (job, done) { | ||
// assert.ok(job.properties()["isPaused"]); | ||
// job.unpause(done); | ||
// }, | ||
// function (job, done) { | ||
// tutils.pollUntil( | ||
// job, | ||
// function (j) { | ||
// return !j.properties()["isPaused"]; | ||
// }, | ||
// 10, | ||
// done | ||
// ); | ||
// }, | ||
// function (job, done) { | ||
// assert.ok(!job.properties()["isPaused"]); | ||
// job.finalize(done); | ||
// }, | ||
// function (job, done) { | ||
// job.cancel(done); | ||
// } | ||
// ], | ||
// function (err) { | ||
// assert.ok(!err); | ||
// done(); | ||
// } | ||
// ); | ||
// }); | ||
Async.chain([ | ||
function (done) { | ||
service.jobs().search('search index=_internal | head 1 | sleep 5', { id: sid }, done); | ||
}, | ||
function (job, done) { | ||
job.pause(done); | ||
}, | ||
function (job, done) { | ||
tutils.pollUntil( | ||
job, | ||
function (j) { | ||
return j.properties()["isPaused"]; | ||
}, | ||
10, | ||
done | ||
); | ||
}, | ||
function (job, done) { | ||
assert.ok(job.properties()["isPaused"]); | ||
job.unpause(done); | ||
}, | ||
function (job, done) { | ||
tutils.pollUntil( | ||
job, | ||
function (j) { | ||
return !j.properties()["isPaused"]; | ||
}, | ||
10, | ||
done | ||
); | ||
}, | ||
function (job, done) { | ||
assert.ok(!job.properties()["isPaused"]); | ||
job.finalize(done); | ||
}, | ||
function (job, done) { | ||
job.cancel(done); | ||
} | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
} | ||
); | ||
}); | ||
@@ -402,41 +394,38 @@ it("Callback#Set TTL", function (done) { | ||
// Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. | ||
// | ||
// | ||
// it("Callback#Set priority", function (done) { | ||
// var sid = getNextId(); | ||
// var originalPriority = 0; | ||
// var that = this; | ||
it("Callback#Set priority", function (done) { | ||
var sid = getNextId(); | ||
var originalPriority = 0; | ||
var that = this; | ||
// var service = this.service.specialize("nobody", "sdkappcollection"); | ||
var service = this.service.specialize("nobody", "sdkappcollection"); | ||
// Async.chain([ | ||
// function (done) { | ||
// service.jobs().search('search index=_internal | head 1 | sleep 5', { id: sid }, done); | ||
// }, | ||
// function (job, done) { | ||
// job.track({}, { | ||
// ready: function (job) { | ||
// done(null, job); | ||
// } | ||
// }); | ||
// }, | ||
// function (job, done) { | ||
// var priority = job.properties()["priority"]; | ||
// assert.ok(priority, 5); | ||
// job.setPriority(priority + 1, done); | ||
// }, | ||
// function (job, done) { | ||
// job.fetch(done); | ||
// }, | ||
// function (job, done) { | ||
// job.cancel(done); | ||
// } | ||
// ], | ||
// function (err) { | ||
// assert.ok(!err); | ||
// done(); | ||
// } | ||
// ); | ||
// }); | ||
Async.chain([ | ||
function (done) { | ||
service.jobs().search('search index=_internal | head 1 | sleep 5', { id: sid }, done); | ||
}, | ||
function (job, done) { | ||
job.track({}, { | ||
ready: function (job) { | ||
done(null, job); | ||
} | ||
}); | ||
}, | ||
function (job, done) { | ||
var priority = job.properties()["priority"]; | ||
assert.ok(priority, 5); | ||
job.setPriority(priority + 1, done); | ||
}, | ||
function (job, done) { | ||
job.fetch(done); | ||
}, | ||
function (job, done) { | ||
job.cancel(done); | ||
} | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
} | ||
); | ||
}); | ||
@@ -632,2 +621,70 @@ it("Callback#Search log", function (done) { | ||
it("Callback#Oneshot search with json results", function (done) { | ||
var sid = getNextId(); | ||
var that = this; | ||
Async.chain([ | ||
function (done) { | ||
that.service.jobs().oneshotSearch('search index=_internal | head 1 | stats count', { id: sid, output_mode: 'json' }, done); | ||
}, | ||
function (results, done) { | ||
assert.ok(results); | ||
assert.ok(results.fields); | ||
assert.strictEqual(results.fields.length, 1); | ||
done(); | ||
} | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
} | ||
); | ||
}); | ||
it("Callback#Oneshot search with xml results", function (done) { | ||
var sid = getNextId(); | ||
var that = this; | ||
Async.chain([ | ||
function (done) { | ||
that.service.jobs().oneshotSearch('search index=_internal | head 2 | stats count', { id: sid, output_mode: 'xml' }, done); | ||
}, | ||
function (results, done) { | ||
assert.ok(results); | ||
assert.ok(results.includes('<field>count</field>')); | ||
assert.ok(results.includes('<value><text>2</text></value>')); | ||
done(); | ||
} | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
} | ||
); | ||
}); | ||
it("Callback#Oneshot search with csv results", function (done) { | ||
var sid = getNextId(); | ||
var that = this; | ||
Async.chain([ | ||
function (done) { | ||
that.service.jobs().oneshotSearch('makeresults count=3 | streamstats count | eval foo="bar" | fields - _time', { id: sid, output_mode: 'csv' }, done); | ||
}, | ||
function (results, done) { | ||
assert.ok(results); | ||
assert.ok(results.includes('count,foo')); | ||
assert.ok(results.includes('1,bar')); | ||
assert.ok(results.includes('2,bar')); | ||
assert.ok(results.includes('3,bar')); | ||
done(); | ||
} | ||
], | ||
function (err) { | ||
assert.ok(!err); | ||
done(); | ||
} | ||
); | ||
}); | ||
it("Callback#Oneshot search with no results", function (done) { | ||
@@ -634,0 +691,0 @@ var sid = getNextId(); |
@@ -107,3 +107,3 @@ | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdk-app-collection" }); | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection" }); | ||
@@ -176,3 +176,3 @@ Async.chain([ | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdk-app-collection" }); | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection" }); | ||
@@ -200,2 +200,43 @@ Async.chain( | ||
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) { | ||
@@ -240,3 +281,3 @@ var name = "jssdk_savedsearch_" + getNextId(); | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdk-app-collection" }); | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection" }); | ||
@@ -359,3 +400,3 @@ Async.chain( | ||
it("Callback#delete test saved searches", function (done) { | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdk-app-collection" }); | ||
var searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection" }); | ||
searches.fetch(function (err, searches) { | ||
@@ -389,3 +430,3 @@ var searchList = searches.list(); | ||
it("Callback#setupInfo succeeds", function (done) { | ||
var app = new splunkjs.Service.Application(this.service, "sdk-app-collection"); | ||
var app = new splunkjs.Service.Application(this.service, "sdkappcollection"); | ||
app.setupInfo(function (err, content, app) { | ||
@@ -415,3 +456,3 @@ // This error message was removed in modern versions of Splunk | ||
it("Callback#updateInfo failure", function (done) { | ||
var app = new splunkjs.Service.Application(this.loggedOutService, "sdk-app-collection"); | ||
var app = new splunkjs.Service.Application(this.loggedOutService, "sdkappcollection"); | ||
app.updateInfo(function (err, info, app) { | ||
@@ -418,0 +459,0 @@ assert.ok(err); |
@@ -41,3 +41,3 @@ | ||
function (done) { | ||
service.views({ owner: "admin", app: "sdk-app-collection" }).create({ name: name, "eai:data": originalData }, done); | ||
service.views({ owner: "admin", app: "sdkappcollection" }).create({ name: name, "eai:data": originalData }, done); | ||
}, | ||
@@ -44,0 +44,0 @@ function (view, done) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
7854162
8.28%268
9.39%147289
0.55%400
31.15%152
0.66%13
8.33%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated
Updated