Constructor for splunkjs.Service.Properties
Constructor for splunkjs.Service.Properties
Name | Type | Description |
---|---|---|
service | splunkjs.Service | A service instance |
init: function(service) {
var namespace = {owner: "-", app: "-"};
this._super(service, this.path(), namespace);
},
Create a property file
Name | Type | Description |
---|---|---|
filename | String | A name for this property file |
callback | Function | A callback with the created property file: |
var properties = service.properties();
properties.create("myprops", function(err, newFile) {
console.log("CREATED");
});
create: function(filename, callback) {
// If someone called us with the default style of (params, callback),
// lets make it work
if (utils.isObject(filename)) {
filename = filename["__conf"];
}
callback = callback || function() {};
var that = this;
var req = this.post("", {__conf: filename}, function(err, response) {
if (err) {
callback(err);
}
else {
var entity = new root.PropertyFile(that.service, filename);
entity.refresh(function() {
if (req.wasAborted) {
return; // aborted, so ignore
}
else {
callback.apply(null, arguments);
}
});
}
});
return req;
}
});
Create a local instance of an entity
Name | Type | Description |
---|---|---|
props | Object | The properties for this entity |
instantiateEntity: function(props) {
return new root.PropertyFile(this.service, props.name, this.namespace);
},
REST path for this resource (with no namespace)
path: function() {
return Paths.properties;
},
Whether or not to call refresh()
after an entity is instantiated locally. By default we don't refresh the entity, as the endpoint will return (echo) the created entities when we list it.
refreshOnEntityInstantiation: true,
Whether or not to call refresh()
after an entity is created. By default we don't refresh the entity, as the endpoint will return (echo) the created entity
refreshOnEntityCreation: true,
Retrieve the author information for this collection
paging: function() {
return this._paging;
},
Check whether a specific entity exists
Check to see if the collection contains a specific entity, and if so, return that entity.
Name | Type | Description |
---|---|---|
id | String | The name of the entity to retrieve |
namespace | Object | Namespace information (owner, app, sharing) |
var apps = service.apps();
apps.refresh(function(err, apps) {
var app = apps.contains("search");
console.log("Search App Found: " + !!app);
// `app` contains the Application object.
});
contains: function(id, namespace) {
if (utils.isEmpty(namespace)) {
namespace = null;
}
if (!id) {
throw new Error("Must suply a non-empty name.");
}
var fullPath = null;
if (this._entitiesByName.hasOwnProperty(id)) {
var entities = this._entitiesByName[id];
if (entities.length === 1 && !namespace) {
// If there is only one entity with the
// specified name and the user did not
// specify a namespace, then we just
// return it
return entities[0];
}
else if (entities.length === 1 && namespace) {
// If we specified a namespace, then we
// only return the entity if it matches
// the full path
fullPath = this.service.fullpath(entities[0].path(), namespace);
if (entities[0].qualifiedPath === fullPath) {
return entities[0];
}
else {
return null;
}
}
else if (entities.length > 1 && !namespace) {
// If there is more than one entity and we didn't
// specify a namespace, then we return an error
// saying the match is ambiguous
throw new Error("Ambiguous match for name '" + id + "'");
}
else {
// There is more than one entity, and we do have
// a namespace, so we try and find it
for(var i = 0; i < entities.length; i++) {
var entity = entities[i];
fullPath = this.service.fullpath(entities[i].path(), namespace);
if (entity.qualifiedPath === fullPath) {
return entity;
}
}
}
}
else {
return null;
}
}
});
Retrieve a list of all entities in the collection
Return the list of all the entities in this collection.
Name | Type | Description |
---|---|---|
callback | Function | A callback with the list of entities: |
var apps = service.apps();
apps.refresh(function(err, apps) {
var appList = apps.list();
console.log(appList.length);
});
list: function(callback) {
callback = callback || function() {};
return utils.clone(this._entities);
},
Fetch a specific entity.
Return a specific entity given its name.
Name | Type | Description |
---|---|---|
name | String | The name of the entity to retrieve |
namespace | Object | Namespace information (owner, app, sharing) |
var apps = service.apps();
apps.item("search", function(err, app) {
console.log(app.properties());
})
item: function(name, namespace) {
return this.contains(name, namespace);
},
Refresh the resource
This will unconditionally refresh the object from the server and load it up.
Name | Type | Description |
---|---|---|
options | Object | Dictionary of collection filtering and pagination options |
callback | Function | A callback when the object is retrieved: |
refresh: function(options, callback) {
if (!callback && utils.isFunction(options)) {
callback = options;
options = {};
}
callback = callback || function() {};
options = options || {};
if (!options.count) {
options.count = 0;
}
var recursive = false;
if (options.hasOwnProperty("recursive")) {
recursive = options.recursive;
delete options.recursive;
}
var that = this;
var req = that.get("", options, function(err, response) {
if (err) {
callback(err);
}
else {
that._load(response.data);
if (that.refreshOnEntityInstantiation && recursive) {
var wasAbortedAlready = false;
var fns = [];
utils.forEach(that._entities, function(entity) {
fns.push(function(done) {
entity.refresh({recursive: true}, function() {
if (req.wasAborted) {
if (!wasAbortedAlready) {
wasAbortedAlready = true;
}
}
else {
callback.apply(null, arguments);
}
});
});
});
Async.parallel(fns, function(err) {
callback(err, that);
});
}
else {
callback(null, that);
}
}
});
return req;
},
Retrieve the updated time for this collection
updated: function() {
return this._updated;
},
Retrieve the links information for this collection
links: function() {
return this._links;
},
Retrieve the state for this resource
This will retrieve the current full state for this resource.
state: function() {
return this._state;
}
});
Retrieve the properties for this resource
This will retrieve the current properties for this resource.
properties: function() {
return this._properties;
},
Perform a relative DELETE request
Perform a relative DELETE request on this endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append at the end of the path |
params | Object | A dictionary of parameters to add to the query string |
callback | Function | A callback to be invoked when the request is complete: |
// Will make a request to {service.prefix}/search/jobs/123456
var endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
endpoint.delete("", {}, function() { console.log("DELETED"))});
del: function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.del(
url,
params,
callback
);
}
});
Perform a relative POST request
Perform a relative POST request on this endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append at the end of the path |
params | Object | A dictionary of parameters to add to the body |
callback | Function | A callback to be invoked when the request is complete: |
// Will make a request to {service.prefix}/search/jobs/123456/control
var endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});
post: function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.post(
url,
params,
callback
);
},
Perform a relative GET request
Perform a relative GET request on this endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append at the end of the path |
params | Object | A dictionary of parameters to add to the query string |
callback | Function | A callback to be invoked when the request is complete: |
// Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
var endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});
get: function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.get(
url,
params,
callback
);
},