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

Dictionary of optional parameters: scheme, host, port, username, password, owner, app, sessionKey

Return

splunkjs.Service. A splunkjs.Service instance

users

splunkjs.Service.users
Endpoint: authorization/users

Get an instance of the Users collection

The Users collection allows you to list users, create new ones, get a specific user, etc.

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

Get an instance of the Views collection

The Views collection allows you to list views, create new ones, get a specific user, etc.

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);
     }
 });

log

splunkjs.Service.log
Endpoint: receivers/simple

Log 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, host, host_regex, source, sourcetype

callback Function

A callback when the event was submitted: (err, result)

Examples

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

apps

splunkjs.Service.apps
Endpoint: apps/local

Get an instance of the Applications collection

The Applications collection allows you to list installed applications, create new ones, etc.

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()); });

indexes

splunkjs.Service.indexes
Endpoint: data/indexes

Get an instance of the Indexes collection

The Indexes collection allows you to list indexes, create new indexes, update indexes, etc.

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.
 });

parse

splunkjs.Service.parse
Endpoint: search/parser

Parse a search string

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

callback Function

A callback with the parse info: (err, parse)

Examples

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

serverInfo

splunkjs.Service.serverInfo
Endpoint: server/info

Get the server info

Syntax

serverInfo: function(callback)

Parameters

Name Type Description
callback Function

A callback with the server info: (err, info)

Examples

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

currentUser

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

Get the current user

Get the current logged in user

Syntax

currentUser: function(callback)

Parameters

Name Type Description
callback Function

A callback with the user instance: (err, user)

Examples

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

oneshotSearch

splunkjs.Service.oneshotSearch
Endpoint: search/jobs

Create a oneshot search job

Create a oneshot search job using the specified 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.

namespace Object

Namespace information (owner, app, sharing)

callback Function

A callback 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);
 });

savedSearches

splunkjs.Service.savedSearches
Endpoint: saved/searches

Get an instance of the SavedSearches collection

The SavedSearches collection allows you to list saved searches, create new ones, update a saved search, etc.

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);
 });

configurations

splunkjs.Service.configurations
Endpoint: configs

Get an instance of the Configurations collection

The Configurations collection allows you to list configuration files, create new files, get specific files, etc.

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()); 
     });
});

specialize

splunkjs.Service.specialize

Create a more specialized clone of this service

This will create a more specialized version of the current Service instance, which is useful in cases where a specific owner or app need to be specified.

Syntax

specialize: function(owner, app)

Parameters

Name Type Description
owner String

The specialized owner of the new service

app String

The specialized app of the new sevice

Return

splunkjs.Service. The specialized service.

Examples

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

jobs

splunkjs.Service.jobs
Endpoint: search/jobs

Get an instance of the Jobs collection

The Jobs collection allows you to list jobs, create new ones, get a specific job, etc.

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);
     }
 });

request

splunkjs.Context.request

Perform a request

Syntax

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

Parameters

Name Type Description
path String

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

method String

HTTP method (one of GET | POST | DELETE)

headers Object

Object of headers for this request

body Object

Body of parameters for this request

callback Function

Callback for when the request is complete: (err, response)

post

splunkjs.Context.post

Perform a POST request

Syntax

post: function(path, params, callback)

Parameters

Name Type Description
path String

Path to request

params Object

Body parameters for this request

callback Function

Callback for when the request is complete: (err, response)

del

splunkjs.Context.del

Perform a DELETE request

Syntax

del: function(path, params, callback)

Parameters

Name Type Description
path String

Path to request

params Object

Query parameters for this request

callback Function

Callback for when the request is complete: (err, response)

get

splunkjs.Context.get

Perform a GET request

Syntax

get: function(path, params, callback)

Parameters

Name Type Description
path String

Path to request

params Object

Query parameters for this request

callback Function

Callback for when the request is complete: (err, response)

fullpath

splunkjs.Context.fullpath

Convert partial paths to fully qualified ones

Convert any partial path into a full path containing the full owner and app prefixes if necessary

Syntax

fullpath: function(path, namespace)

Parameters

Name Type Description
path String

Partial path

Return

String. Fully qualified path