Constructor for splunkjs.Service.Application
Constructor for splunkjs.Service.Application
Name | Type | Description |
---|---|---|
service | splunkjs.Service | A service instance |
name | String | The name of the application |
init: function(service, name) {
this.name = name;
this._super(service, this.path(), {});
this.setupInfo = utils.bind(this, this.setupInfo);
this.updateInfo = utils.bind(this, this.updateInfo);
},
Retrieve any available update information for this app
Name | Type | Description |
---|---|---|
callback | Function | A callback when the update information is retrieved: |
var app = service.apps().item("MyApp");
app.updateInfo(function(err, info, app) {
console.log("UPDATE INFO: ", info);
});
updateInfo: function(callback) {
callback = callback || function() {};
var that = this;
return this.get("update", {}, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, response.data.entry.content, that);
}
});
}
});
Retrieve information about the setup for this app
Name | Type | Description |
---|---|---|
callback | Function | A callback when the setup information is retrieved: |
var app = service.apps().item("app");
app.setup(function(err, info, search) {
console.log("SETUP INFO: ", info);
});
setupInfo: function(callback) {
callback = callback || function() {};
var that = this;
return this.get("setup", {}, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, response.data.entry.content, that);
}
});
},
REST path for this resource (with no namespace)
path: function() {
return Paths.apps + "/" + encodeURIComponent(this.name);
},
Whether or not to call fetch()
after an update to fetch the updated item.
fetchOnUpdate: true,
Retrieve the updated time for this entity
updated: function() {
return this._updated;
},
Reload the entity
This will reload the entity on the server.
Name | Type | Description |
---|---|---|
callback | Function | A callback 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);
}
});
}
});
Refresh the resource
This will fetch the object from the server and load it up.
Name | Type | Description |
---|---|---|
options | Object | Optional dictionary of collection filtering and pagination options |
callback | Function | A callback 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.entry);
callback(null, that);
}
});
},
Retrieve the fields information for this entity
fields: function() {
return this._fields;
},
Enable the entity
This will enable the entity on the server.
Name | Type | Description |
---|---|---|
callback | Function | A callback 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);
}
});
},
Disable the entity
This will disable the entity on the server.
Name | Type | Description |
---|---|---|
callback | Function | A callback 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);
}
});
},
Update the entity
This will update the entity on the server.
Name | Type | Description |
---|---|---|
props | Object | Properties to be updated the object with. |
callback | Function | A callback when the object is updated: |
update: function(props, callback) {
callback = callback || function() {};
if (props.hasOwnProperty("name")) {
throw new Error("Cannot set 'name' field in 'update'");
}
var that = this;
var req = this.post("", props, function(err, response) {
if (!err && !that.fetchOnUpdate) {
that._load(response.data.entry);
callback(err, that);
}
else if (!err && that.fetchOnUpdate) {
that.fetch(function() {
if (req.wasAborted) {
return; // aborted, so ignore
}
else {
callback.apply(null, arguments);
}
});
}
else {
callback(err, that);
}
});
return req;
},
Delete the entity
This will tell the server to delete this entity.
Name | Type | Description |
---|---|---|
callback | Function | A callback when the object is deleted: |
remove: function(callback) {
callback = callback || function() {};
var that = this;
return this.del("", {}, function(err) {
callback(err);
});
},
Retrieve the ACL information for this entity
acl: function() {
return this._acl;
},
Retrieve the published time for this entity
published: function() {
return this._published;
},
Load the resource, also storing the properties.
Name | Type | Description |
---|---|---|
properties | Object | The properties for this resource |
_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;
},
Retrieve the author information for this entity
author: function() {
return this._author;
},
Retrieve the links information for this entity
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
);
},