Returns a boolean of whether this exists in this data model or not.
Returns a boolean of whether this exists in this data model or not.
Returns true if this data model has object with specified name, false otherwise.
hasObject: function(name) {
return utils.contains(this.objectNames, name);
},
Constructor for splunkjs.Service.DataModel
.
Name | Type | Description |
---|---|---|
service | splunkjs.Service | A |
name | String | The name for the new data model. |
namespace | Object | (Optional) namespace information: |
props | Object | Properties of this data model: |
init: function(service, name, namespace, props) {
// If not given a 4th arg, assume the namespace was omitted
if (!props) {
props = namespace;
namespace = {};
}
this.name = name;
this._super(service, this.path(), namespace);
this.acceleration = JSON.parse(props.content.acceleration) || {};
if (this.acceleration.hasOwnProperty("enabled")) {
// convert the enabled property to a boolean
this.acceleration.enabled = !!this.acceleration.enabled;
}
// concise=0 (false) forces the server to return all details of the newly created data model.
// we do not want a summary of this data model
if (!props.hasOwnProperty("concise") || utils.isUndefined(props.concise)) {
this.concise = "0";
}
var dataModelDefinition = JSON.parse(props.content.description);
this.objectNames = dataModelDefinition.objectNameList;
this.displayName = dataModelDefinition.displayName;
this.description = dataModelDefinition.description;
// Parse the objects for this data model
var objs = dataModelDefinition.objects;
this.objects = [];
for (var i = 0; i < objs.length; i++) {
this.objects.push(new root.DataModelObject(objs[i], this));
}
this.remove = utils.bind(this, this.remove);
this.update = utils.bind(this, this.update);
},
Returns a boolean indicating whether acceleration is enabled or not.
true if acceleration is enabled, false otherwise.
isAccelerated: function() {
return !!this.acceleration.enabled;
},
Returns a data model object from this data model with the specified name if it exists, null otherwise.
a data model object.
objectByName: function(name) {
for (var i = 0; i < this.objects.length; i++) {
if (this.objects[i].name === name) {
return this.objects[i];
}
}
return null;
},
Retrieves the REST endpoint path for this resource (with no namespace).
path: function() {
return Paths.dataModels + "/" + encodeURIComponent(this.name);
},
Updates the data model on the server, used to update acceleration settings.
Name | Type | Description |
---|---|---|
props | Object | A dictionary of properties to update the object with: |
callback | Function | A function to call when the data model is updated: |
update: function(props, callback) {
if (utils.isUndefined(callback)) {
callback = props;
props = {};
}
callback = callback || function() {};
if (!props) {
callback(new Error("Must specify a props argument to update a data model."));
return; // Exit if props isn't set, to avoid calling the callback twice.
}
if (props.hasOwnProperty("name")) {
callback(new Error("Cannot set 'name' field in 'update'"), this);
return; // Exit if the name is set, to avoid calling the callback twice.
}
var updatedProps = {
acceleration: JSON.stringify({
enabled: props.accceleration && props.acceleration.enabled || this.acceleration.enabled,
earliest_time: props.accceleration && props.acceleration.earliestTime || this.acceleration.earliestTime,
cron_schedule: props.accceleration && props.acceleration.cronSchedule || this.acceleration.cronSchedule
})
};
var that = this;
return this.post("", updatedProps, function(err, response) {
if (err) {
callback(err, that);
}
else {
var dataModelNamespace = utils.namespaceFromProperties(response.data.entry[0]);
callback(null, new root.DataModel(that.service, response.data.entry[0].name, dataModelNamespace, response.data.entry[0]));
}
});
}
});
Loads the entity and stores the properties.
Name | Type | Description |
---|---|---|
properties | Object | The properties for this entity. |
_load: function(properties) {
properties = utils.isArray(properties) ? properties[0] : properties;
// Initialize the properties to
// empty values
properties = properties || {
content: {},
fields: {},
acl: {},
links: {}
};
this._super(properties);
// Take out the entity-specific content
this._properties = properties.content || {};
this._fields = properties.fields || this._fields || {};
this._acl = properties.acl || {};
this._links = properties.links || {};
this._author = properties.author || null;
this._updated = properties.updated || null;
this._published = properties.published || null;
},
Retrieves the access control list (ACL) information for this entity, which contains the permissions for accessing the entity.
The ACL.
acl: function() {
return this._acl;
},
Retrieves the author information for this entity.
The author.
author: function() {
return this._author;
},
Performs a relative DELETE request on an endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append to the endpoint path. |
params | Object | A dictionary of entity-specific parameters to add to the query string. |
callback | Function | A function to call 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
);
}
});
Disables the entity on the server.
Name | Type | Description |
---|---|---|
callback | Function | A function to call when the object is disabled: |
disable: function(callback) {
callback = callback || function() {};
var that = this;
this.post("disable", {}, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, that);
}
});
},
Enables the entity on the server.
Name | Type | Description |
---|---|---|
callback | Function | A function to call when the object is enabled: |
enable: function(callback) {
callback = callback || function() {};
var that = this;
this.post("enable", {}, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, that);
}
});
},
Refreshes the entity by fetching the object from the server and loading it.
Name | Type | Description |
---|---|---|
options | Object | An optional dictionary of collection filtering and pagination options: |
callback | Function | A function to call when the object is retrieved: |
fetch: function(options, callback) {
if (!callback && utils.isFunction(options)) {
callback = options;
options = {};
}
callback = callback || function() {};
options = options || {};
var that = this;
return this.get("", options, function(err, response) {
if (err) {
callback(err);
}
else {
that._load(response.data ? response.data.entry : null);
callback(null, that);
}
});
},
A static property that indicates whether to call fetch
after an update to get the updated entity. By default, the entity is not fetched because the endpoint returns (echoes) the updated entity.
fetchOnUpdate: false,
Retrieves the fields information for this entity, indicating which fields are wildcards, required, and optional.
The fields information.
fields: function() {
return this._fields;
},
Performs a relative GET request on an endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append to the endpoint path. |
params | Object | A dictionary of entity-specific parameters to add to the query string. |
callback | Function | A function to call 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, isAsync) {
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,
isAsync
);
},
Retrieves the links information for this entity, which is the URI of the entity relative to the management port of a Splunk instance.
The links information.
links: function() {
return this._links;
},
Performs a relative POST request on an endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append to the endpoint path. |
params | Object | A dictionary of entity-specific parameters to add to the body. |
callback | Function | A function to call 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
);
},
Retrieves the current properties for this resource.
The properties.
properties: function() {
return this._properties;
},
Retrieves the published time for this entity.
The published time.
published: function() {
return this._published;
},
Reloads the entity on the server.
Name | Type | Description |
---|---|---|
callback | Function | A function to call when the object is reloaded: |
reload: function(callback) {
callback = callback || function() {};
var that = this;
this.post("_reload", {}, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, that);
}
});
}
});
Deletes the entity from the server.
Name | Type | Description |
---|---|---|
callback | Function | A function to call when the object is deleted: |
remove: function(callback) {
callback = callback || function() {};
var that = this;
return this.del("", {}, function(err) {
callback(err);
});
},
Retrieves the current full state (properties and metadata) of this resource.
The current full state of this resource.
state: function() {
return this._state;
}
});
Retrieves the updated time for this entity.
The updated time.
updated: function() {
return this._updated;
},