apps

splunkjs.Service.apps
Endpoint: apps/local

Gets an instance of the Applications collection, which allows you to list installed apps and retrieve information about them.

Syntax

apps: function()

Return

splunkjs.Service.Collection.

The Applications collection.

Examples

 // List installed apps
 var apps = svc.apps();
 apps.fetch(function(err) { console.log(apps.list()); });

configurations

splunkjs.Service.configurations
Endpoint: configs

Gets an instance of the Configurations collection, which lets you create, list, and retrieve configuration (CONF) files.

Syntax

configurations: function(namespace)

Parameters

Name Type Description
namespace Object

Namespace information (owner, app, sharing).

Return

splunkjs.Service.Configurations.

The Configurations collection.

Examples

 // List all properties in the 'props.conf' file
 var files = svc.configurations();
 files.item("props", function(err, propsFile) {
     propsFile.fetch(function(err, props) {
         console.log(props.properties()); 
     });
});

currentUser

splunkjs.Service.currentUser
Endpoint: authorization/current-context

Gets the user that is currently logged in.

Syntax

currentUser: function(callback)

Parameters

Name Type Description
callback Function

A function to call with the user instance: (err, user).

Examples

 service.currentUser(function(err, user) {
     console.log("Real name: ", user.properties().realname);
 });

indexes

splunkjs.Service.indexes
Endpoint: data/indexes

Gets an instance of the Indexes collection, which lets you create, list, and update indexes.

Syntax

indexes: function(namespace)

Parameters

Name Type Description
namespace Object

Namespace information (owner, app, sharing).

Return

splunkjs.Service.Indexes.

The Indexes collection.

Examples

 // Check if we have an _internal index
 var indexes = svc.configurations();
 indexes.fetch(function(err, indexes) {
     var index = indexes.item("_internal");
     console.log("Was index found: " + !!index);
     // `index` is an Index object.
 });

init

splunkjs.Service.init

Constructor for splunkjs.Service.

Syntax

init: function()

Parameters

Name Type Description
http splunkjs.Http

An instance of a splunkjs.Http class.

params Object

A dictionary of optional parameters:
* scheme: The scheme (http or https) for accessing Splunk.
* host: The host name (the default is localhost).
* port: The port number (the default is 8089).
* username: The Splunk account username, which is used to authenticate the Splunk instance.
* password: The password, which is used to authenticate the Splunk instance.
* owner: The owner (username) component of the namespace context.
* app: The app component of the namespace context.
* sessionKey: The current session token.
* autologin: Enable or disable autologin functionaly (enabled by default).
* version: Version string for Splunk (e.g. 4.3, 4.3.2, 5.0) - defaults to 4.3.

Return

splunkjs.Service.

A new splunkjs.Service instance.

jobs

splunkjs.Service.jobs
Endpoint: search/jobs

Gets an instance of the Jobs collection, which lets you create, list, and retrieve search jobs.

Syntax

jobs: function(namespace)

Parameters

Name Type Description
namespace Object

Namespace information (owner, app, sharing).

Return

splunkjs.Service.Jobs.

The Jobs collection.

Examples

 // List all job IDs
 var jobs = svc.jobs();
 jobs.fetch(function(err, jobs) {
     var list = jobs.list();
     for(var i = 0; i < list.length; i++) {
         console.log("Job " + (i+1) + ": " + list[i].sid);
     }
 });

log

splunkjs.Service.log
Endpoint: receivers/simple

Logs an event to Splunk.

Syntax

log: function(event, params, callback)

Parameters

Name Type Description
event String

The text for this event.

params Object

A dictionary of parameters for indexing:
* index: The index to send events from this input to.
* host: The value to populate in the host field for events from this data input.
* host_regex: A regular expression used to extract the host value from each event.
* source: The source value to fill in the metadata for this input's events.
* sourcetype: The sourcetype to apply to events from this input.

callback Function

A function to call when the event is submitted: (err, result).

Examples

 service.log("A new event", {index: "_internal", sourcetype: "mysourcetype"}, function(err, result) {
     console.log("Submitted event: ", result);
 });

oneshotSearch

splunkjs.Service.oneshotSearch
Endpoint: search/jobs

Creates a oneshot search job from a given search query and parameters.

Syntax

oneshotSearch: function(query, params, namespace, callback)

Parameters

Name Type Description
query String

The search query.

params Object

A dictionary of properties for the job. For details, see the POST search/jobs endpoint in the REST API documentation.

namespace Object

Namespace information (owner, app, sharing).

callback Function

A function to call with the results of the job: (err, results).

Examples

 service.oneshotSearch("search ERROR", {id: "myjob_123"}, function(err, results) {
     console.log("RESULT FIELDS": results.fields);
 });

parse

splunkjs.Service.parse
Endpoint: search/parser

Parses a search query.

Syntax

parse: function(query, params, callback)

Parameters

Name Type Description
query String

The search query to parse.

params Object

An object of options for the parser. For details, see the GET search/parser endpoint in the REST API documentation.

callback Function

A function to call with the parse info: (err, parse).

Examples

 service.parse("search index=_internal | head 1", function(err, parse) {
     console.log("Commands: ", parse.commands);
 });

savedSearches

splunkjs.Service.savedSearches
Endpoint: saved/searches

Gets an instance of the SavedSearches collection, which lets you create, list, and update saved searches.

Syntax

savedSearches: function(namespace)

Parameters

Name Type Description
namespace Object

Namespace information (owner, app, sharing).

Return

splunkjs.Service.SavedSearches.

The SavedSearches collection.

Examples

 // List all # of saved searches
 var savedSearches = svc.savedSearches();
 savedSearches.fetch(function(err, savedSearches) {
     console.log("# Of Saved Searches: " + savedSearches.list().length);
 });

serverInfo

splunkjs.Service.serverInfo
Endpoint: server/info

Gets configuration information about the server.

Syntax

serverInfo: function(callback)

Parameters

Name Type Description
callback Function

A function to call with the server info: (err, info).

Examples

 service.serverInfo(function(err, info) {
     console.log("Splunk Version: ", info.properties().version);
 });

specialize

splunkjs.Service.specialize

Creates a specialized version of the current Service instance for a specific owner and app.

Syntax

specialize: function(owner, app)

Parameters

Name Type Description
owner String

The owner of the specialized service.

app String

The app of the specialized service.

Return

splunkjs.Service.

The specialized Service instance.

Examples

 var svc = ...;
 var newService = svc.specialize("myuser", "unix");

typeahead

splunkjs.Service.typeahead
Endpoint: search/typeahead

Provides auto-complete suggestions for search queries.

Syntax

typeahead: function(prefix, count, callback)

Parameters

Name Type Description
prefix String

The query fragment to autocomplete.

count Number

The number of options to return (optional).

callback Function

A function to call with the autocompletion info: (err, options).

Examples

 service.typeahead("index=", 10, function(err, options) {
     console.log("Autocompletion options: ", options);
 });

users

splunkjs.Service.users
Endpoint: authorization/users

Gets an instance of the Users collection, which lets you create, list, and retrieve users.

Syntax

users: function()

Return

splunkjs.Service.Users.

The Users collection.

Examples

 // List all usernames
 var users = svc.users();
 users.fetch(function(err, users) {
     var list = users.list();
     for(var i = 0; i < list.length; i++) {
         console.log("User " + (i+1) + ": " + list[i].properties().name);
     }
 });

views

splunkjs.Service.views
Endpoint: data/ui/views

Gets an instance of the Views collection, which lets you create, list, and retrieve views (custom UIs built in Splunk's app framework).

Syntax

views: function(namespace)

Parameters

Name Type Description
namespace Object

Namespace information (owner, app, sharing).

Return

splunkjs.Service.Views.

The Views collection.

Examples

 // List all views
 var views = svc.views();
 views.fetch(function(err, views) {
     var list = views.list();
     for(var i = 0; i < list.length; i++) {
         console.log("View " + (i+1) + ": " + list[i].properties().name);
     }
 });

del

splunkjs.Context.del

Performs a DELETE request.

Syntax

del: function(path, params, callback)

Parameters

Name Type Description
path String

The path of the DELETE request.

params Object

The query parameters for this request.

callback Function

The function to call when the request is complete: (err, response).

fullpath

splunkjs.Context.fullpath

Converts a partial path to a fully-qualified path, and if necessary includes the owner and app prefixes.

Syntax

fullpath: function(path, namespace)

Parameters

Name Type Description
path String

Partial path

namespace String

The namespace context, as 'owner/app'.

Return

String.

Fully qualified path

get

splunkjs.Context.get

Performs a GET request.

Syntax

get: function(path, params, callback)

Parameters

Name Type Description
path String

The path of the GET request.

params Object

The query parameters for this request.

callback Function

The function to call when the request is complete: (err, response).

post

splunkjs.Context.post

Performs a POST request.

Syntax

post: function(path, params, callback)

Parameters

Name Type Description
path String

The path of the POST request.

params Object

The query parameters for this request.

callback Function

The function to call when the request is complete: (err, response).

request

splunkjs.Context.request

Performs a request.

Syntax

request: function(path, method, query, post, body, headers, callback)

Parameters

Name Type Description
path String

The request URL (with any query parameters already appended and encoded).

method String

The HTTP method (can be GET, POST, or DELETE).

headers Object

An object of headers for this request.

body Object

The body parameters for this request.

callback Function

The function to call when the request is complete: (err, response).