Splunk JavaScript SDK 0.1.0

Splunk.Logger

Splunk.Logger

A controllable logging module.

log

Splunk.Logger.log

method

Log to the console (equivalent to console.log)

Source (lib/log.js:85)

log: function() {
    if (process.env.LOG_LEVEL >= levels.ALL) {
        _log.apply(null, arguments);
    }
},

error

Splunk.Logger.error

method

Log error to the console (equivalent to console.error)

Source (lib/log.js:96)

error: function() {
    if (process.env.LOG_LEVEL >= levels.ERROR) {
        _error.apply(null, arguments);
    }
},

warn

Splunk.Logger.warn

method

Log warning to the console (equivalent to console.warn)

Source (lib/log.js:107)

warn: function() {
    if (process.env.LOG_LEVEL >= levels.WARN) {
        _warn.apply(null, arguments);
    }
},

info

Splunk.Logger.info

method

Log info to the console (equivalent to console.info)

Source (lib/log.js:118)

info: function() {
    if (process.env.LOG_LEVEL >= levels.INFO) {
        _info.apply(null, arguments);
    }
},

setLevel

Splunk.Logger.setLevel

method

Params

  • level - String,Number

    A string (ALL | INFO | WARN | ERROR | NONE) or number representing the log level

Set the global logging level

Example

 Splunk.Logger.setLevel("WARN");
 Splunk.Logger.setLevel(0); // equivalent to NONE

Source (lib/log.js:136)

setLevel: function(level) {    
    if (utils.isString(level)) {
        if (levels.hasOwnProperty(level)) {
            process.env.LOG_LEVEL = levels[level];
        }
        else {
            process.env.LOG_LEVEL = levels["ERROR"];
        }
    }
    else if (utils.isNumber(level)) {
        process.env.LOG_LEVEL = level;
    }
    else {
        process.env.LOG_LEVEL = levels["ERROR"];
    }
},

Splunk.Http

Splunk.Http

Base class for HTTP abstraction.

This class provides the basic functionality (get/post/delete/request), as well as utilities to construct uniform responses.

Base classes should only override makeRequest and parseJSON

init

Splunk.Http.init

constructor

Params

  • isSplunk - Boolean

    Whether or not this is HTTP instance is for talking with Splunk.

Returns

Splunk.Http A Splunk.Http instance

Constructor for Splunk.Http

Source (lib/http.js:102)

init: function(isSplunk) {
    // Whether or not this HTTP provider is talking to Splunk or not
    this.isSplunk = (isSplunk === undefined ? true : isSplunk);
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this.get                = utils.bind(this, this.get);
    this.del                = utils.bind(this, this.del);
    this.post               = utils.bind(this, this.post);
    this.request            = utils.bind(this, this.request);
    this._buildResponse     = utils.bind(this, this._buildResponse);
},

get

Splunk.Http.get

method

Params

  • url - String

    URL to request

  • headers - Object

    Object of headers for this request

  • params - Object

    Body parameters for this request

  • timeout - Number

    Timeout (currently ignored)

  • callback - Function

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

Perform a POST request

Source (lib/http.js:126)

get: function(url, headers, params, timeout, callback) {
    var encoded_url = url + "?" + root.encode(params);
    var message = {
        method: "GET",
        headers: headers,
        timeout: timeout
    };
    return this.request(encoded_url, message, callback);
},

post

Splunk.Http.post

method

Params

  • url - String

    URL to request

  • headers - Object

    Object of headers for this request

  • params - Object

    Body parameters for this request

  • timeout - Number

    Timeout (currently ignored)

  • callback - Function

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

Perform a POST request

Source (lib/http.js:148)

post: function(url, headers, params, timeout, callback) {
    headers["Content-Type"] = "application/x-www-form-urlencoded";
    var message = {
        method: "POST",
        headers: headers,
        timeout: timeout,
        body: root.encode(params)
    };
    return this.request(url, message, callback);
},

del

Splunk.Http.del

method

Params

  • url - String

    URL to request

  • headers - Object

    Object of headers for this request

  • params - Object

    Query parameters for this request

  • timeout - Number

    Timeout (currently ignored)

  • callback - Function

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

Perform a DELETE request

Source (lib/http.js:171)

del: function(url, headers, params, timeout, callback) {
    var encoded_url = url + "?" + root.encode(params);
    var message = {
        method: "DELETE",
        headers: headers,
        timeout: timeout
    };
    return this.request(encoded_url, message, callback);
},

request

Splunk.Http.request

method

Params

  • url - String

    URL to request (already encoded)

  • message - Object

    Object with values for method, headers, timeout and encoded body

  • Callback - Function

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

Perform a request

This function sets up everything to handle the response from a request, but delegates the actual calling to the subclass using makeRequest.

Source (lib/http.js:195)

request: function(url, message, callback) {
    var wrappedCallback = function(response) {
        callback = callback || function() {};
        if (response.status < 400) {
            callback(null, response);
        }
        else {
            callback(response);
        }
    };
    // Now we can invoke the user-provided HTTP class,
    // passing in our "wrapped" callback
    this.makeRequest(url, message, wrappedCallback);
},

makeRequest

Splunk.Http.makeRequest

method

Params

  • url - String

    URL to request (already encoded)

  • message - Object

    Object with values for method, headers, timeout and encoded body

  • Callback - Function

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

Client-specific request logic

This function encapsulates the actual logic for performing a request, and is meant to be overriden by subclasses.

Source (lib/http.js:224)

makeRequest: function(url, message, callback) {
    throw new Error("UNDEFINED FUNCTION - OVERRIDE REQUIRED"); 
},

parseJson

Splunk.Http.parseJson

method

Params

  • json - String

    JSON to parse

Client-specific JSON parsing logic

This function encapsulates the actual logic for parsing the JSON response.

Source (lib/http.js:239)

parseJson: function(json) {
    throw new Error("UNDEFINED FUNCTION - OVERRIDE REQUIRED");
},

_buildResponse

Splunk.Http._buildResponse

method

Params

  • error - Object

    Error object if there was one for the request

  • response - Object

    The actual response object

  • data - Object

    The response data

Returns

Object A unified response object

Construct a unified response

This function will generate a unified response given the parameters

Source (lib/http.js:256)

_buildResponse: function(error, response, data) {
            var complete_response, json, odata;
            // Parse the JSON data and build the OData response
            // object.
            if (this.isSplunk) {
                json = this.parseJson(data);
                odata = ODataResponse.fromJson(json);  
                // Print any messages that came with the response
                ODataResponse.printMessages(odata);
                complete_response = {
                    response: response,
                    status: (response ? response.statusCode : 0),
                    odata: odata,
                    error: error
                };
            }
            else {
                json = "";
                // We only try to parse JSON if the headers say it is JSON
                if (response && response.headers["content-type"] === "application/json") {
                    json = this.parseJson(data);
                }
                complete_response = {
                    response: response,
                    status: (response ? response.statusCode : 0),
                    json: json,
                    error: error
                };
            }
            return complete_response;
        }
    });
})();

Splunk.Http Module Globals

encode

Splunk.Http.encode

method

Params

  • params - Object

    Parameters to URL-encode

Returns

String URL-encoded query string

Helper function to encode a dictionary of values into a URL-encoded format.

Example

 // should be a=1&b=2&b=3&b=4
 encode({a: 1, b: [2,3,4]})

Source

root.encode = function(params) {
    var encodedStr = "";
    // We loop over all the keys so we encode them.
    for (var key in params) {
        if (params.hasOwnProperty(key)) {
            // Only append the ampersand if we already have
            // something encoded, and the last character isn't
            // already an ampersand
            if (encodedStr && encodedStr[encodedStr.length - 1] !== "&") {
                encodedStr = encodedStr + "&";
            }
            
            // Get the value
            var value = params[key];
            // If it's an array, we loop over each value
            // and encode it in the form &key=value[i]
            if (value instanceof Array) {
                for (var i = 0; i < value.length; i++) {
                    encodedStr = encodedStr + key + "=" + encodeURIComponent(value[i]) + "&";
                }
            }
            else if (typeof value === "object") {
                for(var innerKey in value) {
                    if (value.hasOwnProperty(innerKey)) {
                        var innerValue = value[innerKey];
                        encodedStr = encodedStr + key + "=" + encodeURIComponent(value[innerKey]) + "&";
                    }
                }
            }
            else {
                // If it's not an array, we just encode it
                encodedStr = encodedStr + key + "=" + encodeURIComponent(value);
            }
        }
    }
    return encodedStr;
};

Splunk.Utils

Splunk.Utils

Various utility functions for the Splunk SDK

Splunk.Utils Module Globals

bind

Splunk.Utils.bind

method

Params

  • me - Object

    Object to bind to

  • fn - Function

    Function to bind

Returns

Function The bound function

Bind a function to a specific object

Example

 var obj = {a: 1, b: function() { console.log(a); }};
 var bound = Splunk.Utils.bind(obj, obj.b);
 bound(); // should print 1

Source

root.bind = function(me, fn) { 
    return function() { 
        return fn.apply(me, arguments); 
    }; 
};

trim

Splunk.Utils.trim

method

Params

  • str - String

    The string to trim

Returns

String The trimmed string

Strip a string of all leading and trailing whitespace.

Example

 var a = " aaa ";
 var b = Splunk.Utils.trim(a); //== "aaa"

Source

root.trim = function(str) {
    if (String.prototype.trim) {
        return String.prototype.trim.call(str);
    }
    else {
        return str.replace(/^\\s\\s*/, '').replace(/\\s\\s*$/, '');   
    }
};

indexOf

Splunk.Utils.indexOf

method

Params

  • arr - Array

    The array to search in

  • search - Anything

    The thing to search for

Returns

Number The index of `search` or `-1` if it wasn't found

Whether an array contains a specific object

Example

 var a = ["a", "b', "c"];
 console.log(Splunk.Utils.indexOf(a, "b")) //== 1
 console.log(Splunk.Utils.indexOf(a, "d")) //== -1

Source

root.indexOf = function(arr, search) {
    for(var i=0; i<arr.length; i++) {
        if (arr[i] === search) {
            return i;
        }
    }
    return -1;
};

contains

Splunk.Utils.contains

method

Params

  • arr - Array

    Array to search

  • obj - Anything

    Whether the array contains the element

Returns

Boolean Whether the array contains the element

Whether an array contains a specific object

Example

 var a = {a: 3};
 var b = [{}, {c: 1}, {b: 1}, a];
 var contained = Splunk.Utils.contains(b, a); // should be tree

Source

root.contains = function(arr, obj) {
    arr = arr || [];
    return (root.indexOf(arr, obj) >= 0);
};

startsWith

Splunk.Utils.startsWith

method

Params

  • original - String

    String to search

  • prefix - String

    Prefix to search with

Returns

Boolean Whether the string starts with the prefix

Whether a string starts with a specific prefix.

Example

 var starts = Splunk.Utils.startsWith("splunk-foo", "splunk-");

Source

root.startsWith = function(original, prefix) {
    var matches = original.match("^" + prefix);
    return matches && matches.length > 0 && matches[0] === prefix;  
};

endsWith

Splunk.Utils.endsWith

method

Params

  • original - String

    String to search

  • suffix - String

    Suffix to search with

Returns

Boolean Whether the string ends with the suffix

Whether a string ends with a specific suffix.

Example

 var ends = Splunk.Utils.endsWith("foo-splunk", "-splunk");

Source

root.endsWith = function(original, suffix) {
    var matches = original.match(suffix + "$");
    return matches && matches.length > 0 && matches[0] === suffix;  
};
var toString = Object.prototype.toString;

toArray

Splunk.Utils.toArray

method

Params

  • iterable - Arguments

    Iterable to conver to an array

Returns

Array The converted array

Convert an iterable to an array.

Example

 function() { 
     console.log(arguments instanceof Array); // false
     var arr = console.log(Splunk.Utils.toArray(arguments) instanceof Array); // true
 }

Source

root.toArray = function(iterable) {
    return Array.prototype.slice.call(iterable);
};

isArray

Splunk.Utils.isArray

property

Params

  • obj - Anything

    Parameter to check whether it is an array

Returns

Boolean Whether or not the passed in parameter was an array

Whether or not the argument is an array

Example

 function() { 
     console.log(Splunk.Utils.isArray(arguments)); // false
     console.log(Splunk.Utils.isArray([1,2,3])); // true
 }

Source

root.isArray = Array.isArray || function(obj) {
    return toString.call(obj) === '[object Array]';
};

isFunction

Splunk.Utils.isFunction

method

Params

  • obj - Anything

    Parameter to check whether it is a function

Returns

Boolean Whether or not the passed in parameter was a function

Whether or not the argument is a function

Example

 function() { 
     console.log(Splunk.Utils.isFunction([1,2,3]); // false
     console.log(Splunk.Utils.isFunction(function() {})); // true
 }

Source

root.isFunction = function(obj) {
    return !!(obj && obj.constructor && obj.call && obj.apply);
};

isNumber

Splunk.Utils.isNumber

method

Params

  • obj - Anything

    Parameter to check whether it is a number

Returns

Boolean Whether or not the passed in parameter was a number

Whether or not the argument is a number

Example

 function() { 
     console.log(Splunk.Utils.isNumber(1); // true
     console.log(Splunk.Utils.isNumber(function() {})); // false
 }

Source

root.isNumber = function(obj) {
    return !!(obj === 0 || (obj && obj.toExponential && obj.toFixed));
};

isString

Splunk.Utils.isString

method

Params

  • obj - Anything

    Parameter to check whether it is a string

Returns

Boolean Whether or not the passed in parameter was a string

Whether or not the argument is a string

Example

 function() { 
     console.log(Splunk.Utils.isNumber("abc"); // true
     console.log(Splunk.Utils.isNumber(function() {})); // false
 }

Source

root.isString = function(obj) {
        return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
    };
})();

Splunk.Async

Splunk.Async

Utilities for Async control flow and collection handling

Splunk.Async Module Globals

whilst

Splunk.Async.whilst

method

Params

  • condition - Function

    A function which returns a boolean depending on whether the condition has been met.

  • body - Function

    A function which executes the body of the loop: (done)

  • callback - Function

    A function to be executed when the loop is complete: (err)

An asynchronous while loop

Example

 var i = 0;
 Async.whilst(
     function() { return i++ < 3; },
     function(done) {
         Async.sleep(0, function() { done(); });
     },
     function(err) {
         console.log(i) // == 3;
     }
 );

Source

root.whilst = function(condition, body, callback) {  
    condition = condition || function() { return false; };
    body = body || function(done) { done(); };
    callback = callback || function() {};
    
    var iterationDone = function(err) {
        if (err) {
            callback(err);
        }
        else {
            root.whilst(condition, body, callback);
        }
    };
    
    if (condition()) {
        body(iterationDone);
    }
    else {
        callback(null);
    }
};

parallel

Splunk.Async.parallel

method

Params

  • tasks - Function

    An array of functions: (done)

  • callback - Function

    A function to be executed when all tasks are done or an error occurred: (err, ...)

Execute multiple functions in parallel.

Async.parallel will execute multiple tasks (functions) in parallel, and only call the callback if one of them fails, or when all are complete.

Each task takes a single parameter, which is a callback to be invoked when the task is complete.

The callback will be invoked with the combined results (in order) of all the tasks.

Note that order of execution is not guaranteed, even though order of results is.

Example

 Async.parallel([
     function(done) {
         done(null, 1);
     },
     function(done) {
         done(null, 2, 3);
     }],
     function(err, one, two) {
         console.log(err); // == null
         console.log(one); // == 1
         console.log(two); // == [1,2]
     }
 );

Source

root.parallel = function(tasks, callback) {
    tasks = tasks || [];
    callback = callback || function() {};
    
    if (tasks.length === 0) {
        callback();
    }
    
    var tasksLeft = tasks.length;
    var results = [];
    var doneCallback = function(idx) {
        return function(err) {
            
            if (err) {
                callback(err);
                callback = null;
            }
            else {
                var args = utils.toArray(arguments);  
                args.shift();
                
                if (args.length === 1) {
                    args = args[0];
                }
                results[idx] = args;
                
                if ((--tasksLeft) === 0) {
                    results.unshift(null);
                    if (callback) {
                        callback.apply(null, results);
                    }
                }
            }
        };
    };
    
    for(var i = 0; i < tasks.length; i++) {
        var task = tasks[i];
        task(doneCallback(i));
    }
};

series

Splunk.Async.series

method

Params

  • tasks - Function

    An array of functions: (done)

  • callback - Function

    A function to be executed when all tasks are done or an error occurred: (err, ...)

Execute multiple functions in series.

Async.series will execute multiple tasks (functions) in series, and only call the callback if one of them fails, or when all are complete.

Each task takes a single parameter, which is a callback to be invoked when the task is complete.

The callback will be invoked with the combined results (in order) of all the tasks.

Example

 var keeper = 0;
 Async.series([
     function(done) {
         Async.sleep(10, function() {
             console.log(keeper++); // == 0
             done(null, 1);
         });
     },
     function(done) {
         console.log(keeper++); // == 1
         done(null, 2, 3);
     }],
     function(err, one, two) {
         console.log(err); // == null
         console.log(one); // == 1
         console.log(two); // == [1,2]
     }
 );

Source

root.series = function(tasks, callback) {        
    callback = callback || function() {};
    
    var innerSeries = function(task, restOfTasks, resultsSoFar, callback) {
        if (!task) {
            resultsSoFar.unshift(null);
            callback.apply(null, resultsSoFar);
            return;
        }
        
        task(function(err) {
            if (err) {
                callback(err);
                callback = null;
            }
            else {
                var args = utils.toArray(arguments);
                args.shift();
                if (args.length === 1) {
                    args = args[0];
                }
                resultsSoFar.push(args);
                
                innerSeries(restOfTasks[0], restOfTasks.slice(1), resultsSoFar, callback);
            }
        });
    };
    
    innerSeries(tasks[0], tasks.slice(1), [], callback);
};

parallelMap

Splunk.Async.parallelMap

method

Params

  • vals - Array

    An array of the values to map over.

  • fn - Function

    A (possibly asycnhronous) function to apply to each element: (done)

  • callback - Function

    A function to be executed when all tasks are done or an error occurred: (err, mappedVals)

Map an asynchronous function over an array of values, in parallel.

Async.parallelMap will execute a function over each element in an array in parallel, and only call the callback when all operations are done, or when there is an error.

The callback will be invoked with the resulting array.

Example

 Async.parallelMap(
     [1, 2, 3],
     function(val, idx, done) { 
         if (val === 2) {
             Async.sleep(100, function() { done(null, val+1); });   
         }
         else {
             done(null, val + 1);
         }
     },
     function(err, vals) {
         console.log(vals); // == [2,3,4]
     }
 );

Source

root.parallelMap = function(vals, fn, callback) {     
    callback = callback || function() {};
    
    var tasks = [];
    var createTask = function(val, idx) {
        return function(done) { fn(val, idx, done); };
    };
    
    for(var i = 0; i < vals.length; i++) {
        tasks.push(createTask(vals[i], i));
    }
    
    root.parallel(tasks, function(err) {
        if (err) {
            callback(err);
            callback = null;
        }
        else {
            var args = utils.toArray(arguments);
            args.shift();
            callback(null, args);
        }
    });
};

seriesMap

Splunk.Async.seriesMap

method

Params

  • vals - Array

    An array of the values to map over.

  • fn - Function

    A (possibly asycnhronous) function to apply to each element: (done)

  • callback - Function

    A function to be executed when all tasks are done or an error occurred: (err, mappedVals)

Map an asynchronous function over an array of values, in series.

Async.seriesMap will execute a function over each element in an array in series, and only call the callback when all operations are done, or when there is an error.

The callback will be invoked with the resulting array.

Example

 var keeper = 1;
 Async.seriesMap(
     [1, 2, 3],
     function(val, idx, done) { 
         console.log(keeper++); // == 1, then 2, then 3
         done(null, val + 1);
     },
     function(err, vals) {
         console.log(vals); // == [2,3,4];
     }
 );

Source

root.seriesMap = function(vals, fn, callback) {     
    callback = callback || function() {};
    
    var tasks = [];
    var createTask = function(val, idx) {
        return function(done) { fn(val, idx, done); };
    };
    
    for(var i = 0; i < vals.length; i++) {
        tasks.push(createTask(vals[i], i));
    }
    
    root.series(tasks, function(err) {
        if (err) {
            callback(err);
        }
        else {
            var args = utils.toArray(arguments);
            args.shift();
            callback(null, args);
        }
    });
};

parallelEach

Splunk.Async.parallelEach

method

Params

  • vals - Array

    An array of the values to apply over.

  • fn - Function

    A (possibly asycnhronous) function to apply to each element: (done)

  • callback - Function

    A function to be executed when all tasks are done or an error occurred: (err)

Apply an asynchronous function over an array of values, in parallel.

Async.parallelEach will execute a function over each element in an array in parallel, and only call the callback when all operations are done, or when there is an error.

The callback will be invoked with nothing except a possible error parameter

Example

 var total = 0;
 Async.parallelEach(
     [1, 2, 3],
     function(val, idx, done) { 
         var go = function() {
             total += val;
             done();
         };
         if (idx === 1) {
             Async.sleep(100, go);    
         }
         else {
             go();
         }
     },
     function(err) {
         console.log(total); // == 6
     }
 );

Source

root.parallelEach = function(vals, fn, callback) {     
    callback = callback || function() {};
    
    root.parallelMap(vals, fn, function(err, result) {
        callback(err); 
    });
};

seriesEach

Splunk.Async.seriesEach

method

Params

  • vals - Array

    An array of the values to apply over.

  • fn - Function

    A (possibly asycnhronous) function to apply to each element: (done)

  • callback - Function

    A function to be executed when all tasks are done or an error occurred: (err)

Apply an asynchronous function over an array of values, in series.

Async.seriesEach will execute a function over each element in an array in series, and only call the callback when all operations are done, or when there is an error.

The callback will be invoked with nothing except a possible error parameter

Example

 var results = [1, 3, 6];
 var total = 0;
 Async.seriesEach(
     [1, 2, 3],
     function(val, idx, done) { 
         total += val;
         console.log(total === results[idx]); //== true
         done();
     },
     function(err) {
         console.log(total); //== 6
     }
 );

Source

root.seriesEach = function(vals, fn, callback) {     
    callback = callback || function() {};
    
    root.seriesMap(vals, fn, function(err, result) {
        callback(err); 
    });
};

chain

Splunk.Async.chain

method

Params

  • tasks - Function

    An array of functions: (done)

  • callback - Function

    A function to be executed when the chain is done or an error occurred: (err, ...)

Chain asynchronous tasks.

Async.chain will chain asynchronous together by executing a task, and passing the results to the next task as arguments. If an error occurs at any point, or when the chain completes, the callback will be executed

Each task takes 1-N parameters, where the amount is dependent on the previous task in the chain. The last parameter will always be a function to invoke when the task is complete.

The callback will be invoked with the result of the final task.

Note that err arguments are not passed to individual tasks - they are propagated to the final callback.

Example

Async.chain([
    function(callback) { 
        callback(null, 1, 2);
    },
    function(val1, val2, callback) {
        callback(null, val1 + 1);
    },
    function(val1, callback) {
        callback(null, val1 + 1, 5);
    }],
    function(err, val1, val2) {
        console.log(val1); //== 3
        console.log(val2); //== 5
    }
);

Source

root.chain = function(tasks, callback) {
    callback = callback || function() {};
    
    if (!tasks.length) {
        callback();
    }
    else {
        var innerChain = function(task, restOfTasks, result) {
            var chainCallback = function(err) {
                if (err) {
                    callback(err);
                    callback = function() {};
                }
                else {
                    var args = utils.toArray(arguments);
                    args.shift();
                    innerChain(restOfTasks[0], restOfTasks.slice(1), args);
                }
            };
            
            var args = result;
            if (!restOfTasks.length) {
                args.push(callback);
            }
            else {
                args.push(chainCallback);
            }
            
            task.apply(null, args);
        };
        
        innerChain(tasks[0], tasks.slice(1), []);
    }
};

sleep

Splunk.Async.sleep

method

Params

  • timeout - Number

    The specified timeout in milliseconds.

  • callback - Function

    A function to be executed when the timeout occurs.

Execute a function after a certain delay.

Async.sleep will execute the given function after the specified timeout period. This function mostly exists to make setTimeout adhere to Node.js style function signatures.

Example

Async.sleep(1000, function() { console.log("TIMEOUT");});

Source

root.sleep = function(timeout, callback) {
    setTimeout(function() {
        callback();   
    }, timeout);
};

augment

Splunk.Async.augment

method

Params

  • callback - Function

    The callback to augment.

  • rest - Anything...

    Variable number of arguments to augment the callback with.

Augment a callback with extra parameters

Async.augment will cause a callback to be invoked with the extra specified parameters.

Note that the augmented parameters are appended to the end of the parameter list.

Example

 var callback = function(a, b) {
     console.log(a); //== 1
     console.log(b); //== 2
 };
 var augmented = Async.augment(callback, 2);
 augmented(1);

Source

root.augment = function(callback) {
        var args = Array.prototype.slice.call(arguments, 1);
        return function() {
            var augmentedArgs = Array.prototype.slice.call(arguments);
            for(var i = 0; i < args.length; i++) {
              augmentedArgs.push(args[i]);
            }
            
            callback.apply(null, augmentedArgs);
        };
    };
})();

Splunk.Binding.Context

Splunk.Binding.Context

Abstraction over the Splunk HTTP-wire protocol

This class provides the basic functionality for communicating with a Splunk instance over HTTP. It will handle authentication and authorization, and formatting HTTP requests (GET/POST/DELETE) in the format Splunk expects.

init

Splunk.Binding.Context.init

constructor

Params

  • http - Splunk.Http

    An instance of a Splunk.Http class

  • params - Object

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

Returns

Splunk.Binding.Context A Splunk.Binding.Context instance

Constructor for Splunk.Binding.Context

Source (lib/binding.js:49)

init: function(http, params) {
    if (!(http instanceof Http) && !params) {
        // Move over the params
        params = http;
        http = null;
    }
    
    params = params || {};
    
    this.scheme     = params.scheme || "https";
    this.host       = params.host || "localhost";
    this.port       = params.port || 8089;
    this.username   = params.username || null;  
    this.password   = params.password || null;  
    this.owner      = params.owner || "-";  
    this.app        = params.app;  
    this.sessionKey = params.sessionKey || "";
    
    if (!http) {
        // If there is no HTTP implementation set, we check what platform
        // we're running on. If we're running in the browser, then we instantiate
        // XdmHttp, else, we instantiate NodeHttp.
        if (typeof(window) !== 'undefined') {
            var XdmHttp  = require('./platform/client/easyxdm_http').XdmHttp;
            http = new XdmHttp(this.scheme + "://" + this.host + ":" + this.port);
        }
        else {
            var NodeHttp = require('./platform/node/node_http').NodeHttp;
            http = new NodeHttp();
        }
    }
    
    // Store the HTTP implementation
    this.http = http;
    
    // Store our full prefix, which is just combining together
    // the scheme with the host
    this.prefix = this.scheme + "://" + this.host + ":" + this.port + "/services/json/v1";
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this._headers   = utils.bind(this, this._headers);
    this.fullpath   = utils.bind(this, this.fullpath);
    this.urlify     = utils.bind(this, this.urlify);
    this.get        = utils.bind(this, this.get);
    this.del        = utils.bind(this, this.del);
    this.post       = utils.bind(this, this.post);
    this.login      = utils.bind(this, this.login);
},

_headers

Splunk.Binding.Context._headers

method

Params

  • headers - Object

    Dictionary of headers (optional)

Returns

Object Augmented dictionary of headers

Append Splunk-specific headers

Source (lib/binding.js:108)

_headers: function (headers) {
    headers = headers || {};
    headers["Authorization"] = "Splunk " + this.sessionKey;
    return headers;
},

fullpath

Splunk.Binding.Context.fullpath

method

Params

  • path - String

    Partial path

Returns

String Fully qualified path

Convert partial paths to fully qualified ones

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

Source (lib/binding.js:126)

fullpath: function(path) {
    if (utils.startsWith(path, "/")) {
        return path;
    }  
    if (!this.app) {
        return "/services/" + path;
    }
    var owner = (this.owner === "*" || !this.owner ? "-" : this.owner);
    var app   = (this.app === "*" ? "-" : this.app);
    return "/servicesNS/" + owner + "/" + app + "/" + path; 
},

urlify

Splunk.Binding.Context.urlify

method

Params

  • path - String

    Partial path

Returns

String Fully qualified URL

Convert partial paths to a fully qualified URL

Convert any partial path into a fully qualified URL.

Source (lib/binding.js:152)

urlify: function(path) {
    return this.prefix + this.fullpath(path);
},

login

Splunk.Binding.Context.login

method

Params

  • callback - Function

    Callback to be executed when login is complete: (err, wasSuccessful)

Login to a Splunk instance

Perform authentication to a Splunk instance and store the resulting session key.

Source (lib/binding.js:167)

login: function(callback) {
    var that = this;
    var url = Paths.login;
    var params = { username: this.username, password: this.password };
    callback = callback || function() {};
    var wrappedCallback = function(err, response) {
        if (err) {
            callback(err, false);
        }
        else {
            that.sessionKey = response.odata.results.sessionKey;
            callback(null, true);
        }
    };
    
    this.post(url, params, wrappedCallback);
},

get

Splunk.Binding.Context.get

method

Params

  • path - String

    Path to request

  • params - Object

    Query parameters for this request

  • callback - Function

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

Perform a GET request

Source (lib/binding.js:195)

get: function(path, params, callback) {
    this.http.get(
        this.urlify(path),
        this._headers(),
        params,
        0,
        callback
    );  
},

del

Splunk.Binding.Context.del

method

Params

  • path - String

    Path to request

  • params - Object

    Query parameters for this request

  • callback - Function

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

Perform a DELETE request

Source (lib/binding.js:214)

del: function(path, params, callback) {
    this.http.del(
        this.urlify(path),
        this._headers(),
        params,
        0,
        callback
    );  
},

post

Splunk.Binding.Context.post

method

Params

  • path - String

    Path to request

  • params - Object

    Body parameters for this request

  • callback - Function

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

Perform a POST request

Source (lib/binding.js:233)

post: function(path, params, callback) {
    this.http.post(
        this.urlify(path),
        this._headers(),
        params,
        0,
        callback
    );  
},

request

Splunk.Binding.Context.request

method

Params

  • 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)

Perform a request

Source (lib/binding.js:254)

request: function(path, method, headers, body, callback) {
            this.http.request(
                this.urlify(path),    
                {
                    method: method,
                    headers: this._headers(headers),
                    body: body,
                    timeout: 0
                },
                callback
            );
        }
    });
})();

Splunk.Client.Service

extends Splunk.Binding.Context

Splunk.Client.Service

Root access point to the Splunk REST API

This Service class provides "typed" access to Splunk concepts such as searches, indexes, apps and more, as well as providing convenience methods to authenticate and get more specialized instances of the service.

init

Splunk.Client.Service.init

constructor

Params

  • http - Splunk.Http

    An instance of a Splunk.Http class

  • params - Object

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

Returns

Splunk.Client.Service A Splunk.Client.Service instance

Constructor for Splunk.Client.Service

Source (lib/client.js:51)

init: function() {
    this._super.apply(this, arguments);
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this.specialize     = utils.bind(this, this.specialize);
    this.apps           = utils.bind(this, this.apps);
    this.configurations = utils.bind(this, this.configurations);
    this.indexes        = utils.bind(this, this.indexes);
    this.properties     = utils.bind(this, this.properties);
    this.savedSearches  = utils.bind(this, this.savedSearches);
    this.jobs           = utils.bind(this, this.jobs);
},

specialize

Splunk.Client.Service.specialize

method

Params

  • owner - String

    The specialized owner of the new service

  • app - String

    The specialized app of the new sevice

Returns

Splunk.Client.Service The specialized service.

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.

Example

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

Source (lib/client.js:82)

specialize: function(owner, app) {
    return new root.Service(this.http, {
        scheme: this.scheme,
        host: this.host,   
        port: this.port,       
        username: this.username,
        password: this.password,
        owner: owner,
        app: app, 
        sessionKey: this.sessionKey
    });
},

apps

Splunk.Client.Service.apps

method

apps/local

Returns

Splunk.Client.Collection The Applications collection

Get an instance of the Applications collection

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

Example

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

Source (lib/client.js:113)

apps: function() {
    return new root.Applications(this);
},

configurations

Splunk.Client.Service.configurations

method

configs

Returns

Splunk.Client.Configurations The Configurations collection

Get an instance of the Configurations collection

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

Example

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

Source (lib/client.js:139)

configurations: function() {
    return new root.Configurations(this);
},

indexes

Splunk.Client.Service.indexes

method

data/indexes

Returns

Splunk.Client.Indexes The Indexes collection

Get an instance of the Indexes collection

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

Example

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

Source (lib/client.js:164)

indexes: function() { 
    return new root.Indexes(this);
},

properties

Splunk.Client.Service.properties

method

properties

Returns

Splunk.Client.Properties The Properties collection

Get an instance of the Properties collection

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

Example

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

Source (lib/client.js:190)

properties: function() {
    return new root.Properties(this);
},

savedSearches

Splunk.Client.Service.savedSearches

method

saved/searches

Returns

Splunk.Client.SavedSearches The SavedSearches collection

Get an instance of the SavedSearches collection

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

Example

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

Source (lib/client.js:214)

savedSearches: function() {
    return new root.SavedSearches(this);
},

jobs

Splunk.Client.Service.jobs

method

search/jobs

Returns

Splunk.Client.Jobs The Jobs collection

Get an instance of the Jobs collection

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

Example

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

Source (lib/client.js:240)

jobs: function() {
    return new root.Jobs(this);  
},

oneshotSearch

Splunk.Client.Service.oneshotSearch

method

search/jobs

Params

  • query - String

    The search query

  • params - Object

    A dictionary of properties for the job.

  • callback - Function

    A callback with the results of the job: (err, results)

Create a oneshot search job

Create a oneshot search job using the specified query and parameters.

Example

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

Source (lib/client.js:285)

oneshotSearch: function(query, params, callback) {
        var jobs = new root.Jobs(this);
        jobs.oneshotSearch(query, params, callback);
    }
});

Inherited Methods

get

Splunk.Binding.Context.get

method

Params

  • path - String

    Path to request

  • params - Object

    Query parameters for this request

  • callback - Function

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

Perform a GET request

Source

get: function(path, params, callback) {
    this.http.get(
        this.urlify(path),
        this._headers(),
        params,
        0,
        callback
    );  
},

del

Splunk.Binding.Context.del

method

Params

  • path - String

    Path to request

  • params - Object

    Query parameters for this request

  • callback - Function

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

Perform a DELETE request

Source

del: function(path, params, callback) {
    this.http.del(
        this.urlify(path),
        this._headers(),
        params,
        0,
        callback
    );  
},

post

Splunk.Binding.Context.post

method

Params

  • path - String

    Path to request

  • params - Object

    Body parameters for this request

  • callback - Function

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

Perform a POST request

Source

post: function(path, params, callback) {
    this.http.post(
        this.urlify(path),
        this._headers(),
        params,
        0,
        callback
    );  
},

request

Splunk.Binding.Context.request

method

Params

  • 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)

Perform a request

Source

request: function(path, method, headers, body, callback) {
            this.http.request(
                this.urlify(path),    
                {
                    method: method,
                    headers: this._headers(headers),
                    body: body,
                    timeout: 0
                },
                callback
            );
        }
    });
})();

Splunk.Client.Endpoint

Splunk.Client.Endpoint

Base definition for a Splunk endpoint (specific service + path combination).

This Endpoint class provides convenience methods for the three HTTP verbs used in Splunk. It will automatically prepare the path correctly, and allows for relative calls.

init

Splunk.Client.Endpoint.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • path - String

    A relative endpoint path (e.g. 'search/jobs')

Returns

Splunk.Client.Endpoint A Splunk.Client.Endpoint instance

Constructor for Splunk.Client.Endpoint

Source (lib/client.js:314)

init: function(service, path) {
    if (!service) {
        throw new Error("Passed in a null Service.");
    }
    if (!path) {
        throw new Error("Passed in an empty path.");
    }
    this.service = service;
    this.path = path;
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this.get    = utils.bind(this, this.get);
    this.post   = utils.bind(this, this.post);
},

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source (lib/client.js:350)

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source (lib/client.js:384)

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source (lib/client.js:418)

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Resource

extends Splunk.Client.Endpoint

Splunk.Client.Resource

Base definition for a Splunk "resource" (e.g. index, jobs, etc)

This Resource class provides basic methods for handling Splunk resources, such as validation, property accessor, etc. This class should not be used directly, as most methods are meant to be overridden.

init

Splunk.Client.Resource.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • path - String

    A relative endpoint path (e.g. 'search/jobs')

Returns

Splunk.Client.Resource A Splunk.Client.Resource instance

Constructor for Splunk.Client.Resource

Source (lib/client.js:458)

init: function(service, path) {
    this._super(service, path);
    this._maybeValid = false;
    this._properties = {};
    
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this._invalidate = utils.bind(this, this._invalidate);
    this._load       = utils.bind(this, this._load);
    this._validate   = utils.bind(this, this._validate);
    this.refresh     = utils.bind(this, this.refresh);
    this.read        = utils.bind(this, this.read);
    this.isValid     = utils.bind(this, this.isValid);
    this.properties  = utils.bind(this, this.properties);
},

_invalidate

Splunk.Client.Resource._invalidate

method

Mark the resource as in an invalid state

Source (lib/client.js:480)

_invalidate: function() {
    this._maybeValid = false;
},

_load

Splunk.Client.Resource._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source (lib/client.js:492)

_load: function(properties) {
    this._maybeValid = true;
    this._properties = properties || {};
},

_validate

Splunk.Client.Resource._validate

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Validate if the resource is in a valid state, and refresh it if it is not.

Source (lib/client.js:506)

_validate: function(callback) {
    callback = callback || function() {};
    
    if (!this._maybeValid) {
        this.refresh(callback);
    }
    else {
        callback(null, this);
    }
},

refresh

Splunk.Client.Resource.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source (lib/client.js:528)

refresh: function(callback) {
    throw new Error("MUST BE OVERRIDDEN");
},

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source (lib/client.js:539)

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source (lib/client.js:553)

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source (lib/client.js:568)

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

Inherited Methods

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Entity

extends Splunk.Client.Resource

Splunk.Client.Entity

Base class for a Splunk "entity", which is a well defined construct with certain operations (like "properties", "update", "delete").

This Entity class provides basic methods for handling Splunk entities, such as refreshing them, updating, etc.

init

Splunk.Client.Entity.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • path - String

    A relative endpoint path (e.g. 'search/jobs')

Returns

Splunk.Client.Entity A Splunk.Client.Entity instance

Constructor for Splunk.Client.Entity

Source (lib/client.js:601)

init: function(service, path) {
    this._super(service, path);
    
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this._load      = utils.bind(this, this._load);
    this.refresh    = utils.bind(this, this.refresh);
    this.remove     = utils.bind(this, this.remove);
    this.update     = utils.bind(this, this.update);
},

_load

Splunk.Client.Entity._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source (lib/client.js:620)

_load: function(properties) {
    properties = utils.isArray(properties) ? properties[0] : properties;
    
    this._super(properties);
},

refresh

Splunk.Client.Entity.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source (lib/client.js:636)

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            that._load(response.odata.results);
            callback(null, that);
        }
    });
},

remove

Splunk.Client.Entity.remove

method

Params

  • callback - Function

    A callback when the object is deleted: (err)

Delete the entity

This will tell the server to delete this entity.

Source (lib/client.js:661)

remove: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.del("", {}, function() {
        callback();
    });
},

update

Splunk.Client.Entity.update

method

Params

  • props - Object

    Properties to be updated the object with.

  • callback - Function

    A callback when the object is updated: (err, entity)

Update the entity

This will update the entity on the server.

Source (lib/client.js:681)

update: function(props, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", props, function(err) {
            callback(err, that);
        });
        
        this._invalidate();
    }
});

Inherited Methods

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Collection

extends Splunk.Client.Resource

Splunk.Client.Collection

Base class for a Splunk "collection", which is a well defined construct with certain operations (like "list", "create", etc).

This Collection class provides basic methods for handling Splunk entity collection, such as creating an entity, listing entities, etc.

init

Splunk.Client.Collection.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • path - String

    A relative endpoint path (e.g. 'search/jobs')

  • handlers - Object

    A dictionary of functions to perform specialized operations: item, isSame, loadOnCreate, loadOnItem

Returns

Splunk.Client.Collection A Splunk.Client.Collection instance

Constructor for Splunk.Client.Collection

Source (lib/client.js:717)

init: function(service, path, handlers) {
    this._super(service, path);
    
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this._load    = utils.bind(this, this._load);
    this.refresh  = utils.bind(this, this.refresh);
    this.create   = utils.bind(this, this.create);
    this.list     = utils.bind(this, this.list);
    this.contains = utils.bind(this, this.contains);
    this.item     = utils.bind(this, this.item);
    
    var that = this;
    handlers = handlers || {};
    this._item = handlers.item || function(collection, props) { 
        throw new Error("SHOULD NEVER BE CALLED!");
    };
    this._isSame = handlers.isSame || function(entity, id) { 
        return id === entity.properties().__name;
    };
    this._loadOnCreate = handlers.loadOnCreate || function() { return false; };
    this._loadOnItem = handlers.loadOnItem || function() { return true; };
    
},

_load

Splunk.Client.Collection._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

This will load the properties as well as create a map between entity names to entity IDs (for retrieval purposes).

Source (lib/client.js:753)

_load: function(properties) {
    this._super(properties);
    
    var entities = [];
    var entitiesByName = {};
    var entityPropertyList = properties.results || [];
    for(var i = 0; i < entityPropertyList.length; i++) {
        var props = entityPropertyList[i];
        var entity = this._item(this, props);
        entity._load(props);
        
        // If we don't want to load when we see the item,
        // we still load it (to get things like ID/name),
        // and just invalidate it
        if (!this._loadOnItem()) {
            entity._invalidate();
        }
        entities.push(entity);
        entitiesByName[props.__name] = entity;
    }
    this._entities = entities;
    this._entitiesByName = entitiesByName;
},

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source (lib/client.js:787)

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source (lib/client.js:820)

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

create

Splunk.Client.Collection.create

method

Params

  • params - Object

    A dictionary of properties to create the entity with.

  • callback - Function

    A callback with the created entity: (err, createdEntity)

Create an entity for this collection.

Create an entity on the server for this collection with the specified parameters.

Example

 var apps = service.apps();
 apps.create({name: "NewSearchApp"}, function(err, newApp) {
     console.log("CREATED");
 });

Source (lib/client.js:857)

create: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            var props = response.odata.results;
            if (utils.isArray(props)) {
                props = props[0];
            }
            
            var entity = that._item(that, props);
            entity._load(props);
            if (!that._loadOnCreate()) {
                that._invalidate();
            }
            
            callback(null, entity);
        }
    });
    
    this._invalidate();
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source (lib/client.js:901)

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source (lib/client.js:928)

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

Inherited Methods

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.SavedSearches

extends Splunk.Client.Collection

Splunk.Client.SavedSearches

Represents the Splunk collection of saved searches. You can create and list saved searches using this container, or get a specific one.

init

Splunk.Client.SavedSearches.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.SavedSearches A Splunk.Client.SavedSearches instance

Constructor for Splunk.Client.SavedSearches

Source (lib/client.js:979)

init: function(service) {
        this._super(service, Paths.savedSearches, {
            item: function(collection, props) { 
                return new root.SavedSearch(collection.service, props.__name);
            }
        });
    } 
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

create

Splunk.Client.Collection.create

method

Params

  • params - Object

    A dictionary of properties to create the entity with.

  • callback - Function

    A callback with the created entity: (err, createdEntity)

Create an entity for this collection.

Create an entity on the server for this collection with the specified parameters.

Example

 var apps = service.apps();
 apps.create({name: "NewSearchApp"}, function(err, newApp) {
     console.log("CREATED");
 });

Source

create: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            var props = response.odata.results;
            if (utils.isArray(props)) {
                props = props[0];
            }
            
            var entity = that._item(that, props);
            entity._load(props);
            if (!that._loadOnCreate()) {
                that._invalidate();
            }
            
            callback(null, entity);
        }
    });
    
    this._invalidate();
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.SavedSearch

extends Splunk.Client.Entity

Splunk.Client.SavedSearch

Represents a specific Splunk saved search. You can update, remove and perform various operations on this saved search.

init

Splunk.Client.SavedSearch.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • name - String

    The name of saved search

Returns

Splunk.Client.SavedSearch A Splunk.Client.SavedSearch instance

Constructor for Splunk.Client.SavedSearch

Source (lib/client.js:1009)

init: function(service, name) {
    this.name = name;
    this._super(service, Paths.savedSearches + "/" + encodeURIComponent(name));
    
    this.acknowledge  = utils.bind(this, this.acknowledge);
    this.dispatch     = utils.bind(this, this.dispatch);
    this.history      = utils.bind(this, this.history);
    this.suppressInfo = utils.bind(this, this.suppressInfo);
},

acknowledge

Splunk.Client.SavedSearch.acknowledge

method

saved/searches/{name}/acknowledge

Params

  • callback - Function

    A callback when the saved search was acknowledged: (err, savedSearch)

Acknowledge a saved search

Example

 var savedSearch = service.savedSearches().item("MySavedSearch");
 savedSearch.acknowledge(function(err, search) {
     console.log("ACKNOWLEDGED);
 });

Source (lib/client.js:1034)

acknowledge: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("acknowledge", {}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

dispatch

Splunk.Client.SavedSearch.dispatch

method

saved/searches/{name}/dispatch

Params

  • callback - Function

    A callback when the saved search was dispatched: (err, savedSearch)

Dispatch a saved search

Example

 var savedSearch = service.savedSearches().item("MySavedSearch");
 savedSearch.dispatch(function(err, search) {
     console.log("ACKNOWLEDGED);
 });

Source (lib/client.js:1059)

dispatch: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("dispatch", {}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

history

Splunk.Client.SavedSearch.history

method

saved/searches/{name}/history

Params

  • callback - Function

    A callback when the history is retrieved: (err, history, savedSearch)

Retrieve the history for a saved search.

Example

 var savedSearch = service.savedSearches().item("MySavedSearch");
 savedSearch.history(function(err, history, search) {
     console.log("HISTORY: ", history);
 });

Source (lib/client.js:1084)

history: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("history", {}, function(err, response) {
        callback(err, response.odata.results, that);
    });
},

suppressInfo

Splunk.Client.SavedSearch.suppressInfo

method

saved/searches/{name}/suppress

Params

  • callback - Function

    A callback when the suppression state is retrieved: (err, suppressionState, savedSearch)

Check the suppression state of a saved search.

Example

 var savedSearch = service.savedSearches().item("MySavedSearch");
 savedSearch.history(function(err, suppressionState, search) {
     console.log("STATE: ", suppressionState);
 });

Source (lib/client.js:1108)

suppressInfo: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this.get("suppress", {}, function(err, response) {
            callback(err, response.odata.results, that);
        });
    }
});

Inherited Methods

_load

Splunk.Client.Entity._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source

_load: function(properties) {
    properties = utils.isArray(properties) ? properties[0] : properties;
    
    this._super(properties);
},

refresh

Splunk.Client.Entity.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            that._load(response.odata.results);
            callback(null, that);
        }
    });
},

remove

Splunk.Client.Entity.remove

method

Params

  • callback - Function

    A callback when the object is deleted: (err)

Delete the entity

This will tell the server to delete this entity.

Source

remove: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.del("", {}, function() {
        callback();
    });
},

update

Splunk.Client.Entity.update

method

Params

  • props - Object

    Properties to be updated the object with.

  • callback - Function

    A callback when the object is updated: (err, entity)

Update the entity

This will update the entity on the server.

Source

update: function(props, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", props, function(err) {
            callback(err, that);
        });
        
        this._invalidate();
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Applications

extends Splunk.Client.Collection

Splunk.Client.Applications

Represents the Splunk collection of applications. You can create and list applications using this container, or get a specific one.

init

Splunk.Client.Applications.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.Applications A Splunk.Client.Applications instance

Constructor for Splunk.Client.Applications

Source (lib/client.js:1138)

init: function(service) {
        this._super(service, Paths.apps, {
            item: function(collection, props) {
                return new root.Application(collection.service, props.__name);
            }
        });
    }
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

create

Splunk.Client.Collection.create

method

Params

  • params - Object

    A dictionary of properties to create the entity with.

  • callback - Function

    A callback with the created entity: (err, createdEntity)

Create an entity for this collection.

Create an entity on the server for this collection with the specified parameters.

Example

 var apps = service.apps();
 apps.create({name: "NewSearchApp"}, function(err, newApp) {
     console.log("CREATED");
 });

Source

create: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            var props = response.odata.results;
            if (utils.isArray(props)) {
                props = props[0];
            }
            
            var entity = that._item(that, props);
            entity._load(props);
            if (!that._loadOnCreate()) {
                that._invalidate();
            }
            
            callback(null, entity);
        }
    });
    
    this._invalidate();
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Application

extends Splunk.Client.Entity

Splunk.Client.Application

Represents a specific Splunk application. You can update, remove and perform various operations on this application.

init

Splunk.Client.Application.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • name - String

    The name of the application

Returns

Splunk.Client.Application A Splunk.Client.Application instance

Constructor for Splunk.Client.Application

Source (lib/client.js:1168)

init: function(service, name) {
    this.name = name;
    this._super(service, Paths.apps + "/" + encodeURIComponent(name));
    
    this.setupInfo  = utils.bind(this, this.setupInfo);
    this.updateInfo = utils.bind(this, this.updateInfo);
},

setupInfo

Splunk.Client.Application.setupInfo

method

apps/local/{name}/setup

Params

  • callback - Function

    A callback when the setup information is retrieved: (err, info, app)

Retrieve information about the setup for this app

Example

 var app = service.apps().item("app");
 app.setup(function(err, info, search) {
     console.log("SETUP INFO: ", info);
 });

Source (lib/client.js:1191)

setupInfo: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("setup", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            callback(null, response.odata.results, that);
        }
    });
},

updateInfo

Splunk.Client.Application.updateInfo

method

apps/local/{name}/update

Params

  • callback - Function

    A callback when the update information is retrieved: (err, info, app)

Retrieve any available update information for this app

Example

 var app = service.apps().item("MyApp");
 app.updateInfo(function(err, info, app) {
     console.log("UPDATE INFO: ", info);
 });

Source (lib/client.js:1220)

updateInfo: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this.get("update", {}, function(err, response) {
            if (err) {
                callback(err);
            } 
            else {
                callback(null, response.odata.results, that);
            }
        });
    }
});

Inherited Methods

_load

Splunk.Client.Entity._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source

_load: function(properties) {
    properties = utils.isArray(properties) ? properties[0] : properties;
    
    this._super(properties);
},

refresh

Splunk.Client.Entity.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            that._load(response.odata.results);
            callback(null, that);
        }
    });
},

remove

Splunk.Client.Entity.remove

method

Params

  • callback - Function

    A callback when the object is deleted: (err)

Delete the entity

This will tell the server to delete this entity.

Source

remove: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.del("", {}, function() {
        callback();
    });
},

update

Splunk.Client.Entity.update

method

Params

  • props - Object

    Properties to be updated the object with.

  • callback - Function

    A callback when the object is updated: (err, entity)

Update the entity

This will update the entity on the server.

Source

update: function(props, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", props, function(err) {
            callback(err, that);
        });
        
        this._invalidate();
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Indexes

extends Splunk.Client.Collection

Splunk.Client.Indexes

Represents the Splunk collection of indexes. You can create and list indexes using this container, or get a specific one.

init

Splunk.Client.Indexes.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.Indexes A Splunk.Client.Indexes instance

Constructor for Splunk.Client.Indexes

Source (lib/client.js:1255)

init: function(service) {
    this._super(service, Paths.indexes, {
        item: function(collection, props) {
            return new root.Index(collection.service, props.__name);  
        },
        loadOnCreate: function() { return true; },
        loadOnItem: function() { return true; }
    });
},

create

Splunk.Client.Indexes.create

method

data/indexes

Params

  • name - String

    A name for this index

  • params - Object

    A dictionary of properties to create the entity with.

  • callback - Function

    A callback with the created entity: (err, createdIndex)

Create an index

Create an index with the given name and parameters

Example

 var indexes = service.indexes();
 indexes.create("NewIndex", {assureUTF8: true}, function(err, newIndex) {
     console.log("CREATED");
 });

Source (lib/client.js:1284)

create: function(name, params, callback) {
        params = params || {};
        params["name"] = name;
        
        this._super(params, callback);
    }
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Index

extends Splunk.Client.Entity

Splunk.Client.Index

Represents a specific Splunk index. You can update and submit events to this index.

init

Splunk.Client.Index.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • name - String

    The name of the index

Returns

Splunk.Client.Index A Splunk.Client.Index instance

Constructor for Splunk.Client.Index

Source (lib/client.js:1313)

init: function(service, name) {
    this.name = name;
    this._super(service, Paths.indexes + "/" + encodeURIComponent(name));
    
    this.submitEvent = utils.bind(this, this.submitEvent);
},

submitEvent

Splunk.Client.Index.submitEvent

method

receivers/simple?index={name}

Params

  • event - String

    The text for this event

  • params - Object

    A dictionary of parameters for indexing: host, host_regex, source, sourcetype

  • callback - Function

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

Submit an event to this index

Example

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

Source (lib/client.js:1337)

submitEvent: function(event, params, callback) {
        callback = callback || function() {};
        params = params || {};
        
        // Add the index name to the parameters
        params["index"] = this.name;
        
        var path = Paths.submitEvent + "?" + Http.encode(params);
        var method = "POST";
        var headers = {};
        var body = event;
        
        var that = this;
        this.service.request(path, method, headers, body, function(err, response) {
            if (err) {
                callback(err);
            } 
            else {
                callback(null, response.odata.results, that);
            }
        });
        this._invalidate();
    },
    
    remove: function() {
        throw new Error("Indexes cannot be removed");
    }
});

Inherited Methods

_load

Splunk.Client.Entity._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source

_load: function(properties) {
    properties = utils.isArray(properties) ? properties[0] : properties;
    
    this._super(properties);
},

refresh

Splunk.Client.Entity.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            that._load(response.odata.results);
            callback(null, that);
        }
    });
},

remove

Splunk.Client.Entity.remove

method

Params

  • callback - Function

    A callback when the object is deleted: (err)

Delete the entity

This will tell the server to delete this entity.

Source

remove: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.del("", {}, function() {
        callback();
    });
},

update

Splunk.Client.Entity.update

method

Params

  • props - Object

    Properties to be updated the object with.

  • callback - Function

    A callback when the object is updated: (err, entity)

Update the entity

This will update the entity on the server.

Source

update: function(props, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", props, function(err) {
            callback(err, that);
        });
        
        this._invalidate();
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Properties

extends Splunk.Client.Collection

Splunk.Client.Properties

Represents the Splunk collection of property files. You can create and list files using this container, or get a specific one.

init

Splunk.Client.Properties.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.Properties A Splunk.Client.Properties instance

Constructor for Splunk.Client.Properties

Source (lib/client.js:1386)

init: function(service) {
   this._super(service, Paths.properties, {
       item: function(collection, props) {
           var name = props.__name;
           return new root.PropertyFile(collection.service, name);
       },
       loadOnItem: function() { return false; }
   });  
},

create

Splunk.Client.Properties.create

method

properties

Params

  • filename - String

    A name for this property file

  • callback - Function

    A callback with the created property file: (err, createdFile)

Create a property file

Example

 var properties = service.properties();
 properties.create("myprops", function(err, newFile) {
     console.log("CREATED");
 });

Source (lib/client.js:1412)

create: function(filename, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", {__conf: filename}, function(err, response) {
            if (err) {
                callback(err);
            }
            else {
                var entity = new root.PropertyFile(that.service, filename);
                callback(null, entity);
            }
        });
    }
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.PropertyFile

extends Splunk.Client.Collection

Splunk.Client.PropertyFile

Represents the Splunk collection of stanzas for a specific property file. You can create and list stanzas using this container, or get a specific one.

init

Splunk.Client.PropertyFile.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.PropertyFile A Splunk.Client.PropertyFile instance

Constructor for Splunk.Client.PropertyFile

Source (lib/client.js:1448)

init: function(service, name) {
    this.name = name;
    this._super(service, Paths.properties + "/" + encodeURIComponent(name), {
        item: function(collection, props) {
            var name = props.__name;
            return new root.PropertyStanza(collection.service, collection.name, name);
        },
        loadOnItem: function() { return false; }
    });
},

create

Splunk.Client.PropertyFile.create

method

property/{file_name}

Params

  • stanzaName - String

    A name for this stanza

  • callback - Function

    A callback with the created stanza: (err, createdStanza)

Create a stanza in this property file

Example

 var file = service.properties().item("props");
 file.create("my_stanza", function(err, newStanza) {
     console.log("CREATED");
 });

Source (lib/client.js:1475)

create: function(stanzaName, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", {__stanza: stanzaName}, function(err, response) {
            if (err) {
                callback(err);
            }
            else {
                var entity = new root.PropertyStanza(that.service, that.name, stanzaName);
                callback(null, entity);
            }
        });
    }
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.PropertyStanza

extends Splunk.Client.Entity

Splunk.Client.PropertyStanza

Represents a specific Splunk stanza. You can update and remove this stanza.

init

Splunk.Client.PropertyStanza.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • name - String

    The name of the index

Returns

Splunk.Client.PropertyStanza A Splunk.Client.PropertyStanza instance

Constructor for Splunk.Client.PropertyStanza

Source (lib/client.js:1512)

init: function(service, file, name) {
        this.name = name;
        this._super(service, Paths.properties + "/" + encodeURIComponent(file) + "/" + encodeURIComponent(name));
    } 
});

Inherited Methods

_load

Splunk.Client.Entity._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source

_load: function(properties) {
    properties = utils.isArray(properties) ? properties[0] : properties;
    
    this._super(properties);
},

refresh

Splunk.Client.Entity.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            that._load(response.odata.results);
            callback(null, that);
        }
    });
},

remove

Splunk.Client.Entity.remove

method

Params

  • callback - Function

    A callback when the object is deleted: (err)

Delete the entity

This will tell the server to delete this entity.

Source

remove: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.del("", {}, function() {
        callback();
    });
},

update

Splunk.Client.Entity.update

method

Params

  • props - Object

    Properties to be updated the object with.

  • callback - Function

    A callback when the object is updated: (err, entity)

Update the entity

This will update the entity on the server.

Source

update: function(props, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", props, function(err) {
            callback(err, that);
        });
        
        this._invalidate();
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Configurations

extends Splunk.Client.Collection

Splunk.Client.Configurations

Represents the Splunk collection of configuration files. You can create and list files using this container, or get a specific one.

init

Splunk.Client.Configurations.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.Configurations A Splunk.Client.Configurations instance

Constructor for Splunk.Client.Configurations

Source (lib/client.js:1538)

init: function(service) {
   this._super(service, Paths.properties, {
       item: function(collection, props) {
           var name = props.__name;
           return new root.ConfigurationFile(collection.service, name);
       },
       loadOnItem: function() { return false; }
   });  
},

create

Splunk.Client.Configurations.create

method

properties

Params

  • filename - String

    A name for this property file

  • callback - Function

    A callback with the created configuration file: (err, createdFile)

Create a property file

Example

 var properties = service.configurations();
 configurations.create("myprops", function(err, newFile) {
     console.log("CREATED");
 });

Source (lib/client.js:1564)

create: function(filename, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", {__conf: filename}, function(err, response) {
            if (err) {
                callback(err);
            }
            else {
                var entity = new root.ConfigurationFile(that.service, filename);
                callback(null, entity);
            }
        });
    }
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.ConfigurationFile

extends Splunk.Client.Collection

Splunk.Client.ConfigurationFile

Represents the Splunk collection of stanzas for a specific property file. You can create and list stanzas using this container, or get a specific one.

init

Splunk.Client.ConfigurationFile.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.ConfigurationFile A Splunk.Client.ConfigurationFile instance

Constructor for Splunk.Client.ConfigurationFile

Source (lib/client.js:1600)

init: function(service, name) {
    this.name = name;
    var path = Paths.configurations + "/conf-" + encodeURIComponent(name);
    this._super(service, path, {
        item: function(collection, props) {
            var name = props.__name;
            return new root.ConfigurationStanza(collection.service, collection.name, name);
        },
        loadOnCreate: function() { return true; }
    });
},

create

Splunk.Client.ConfigurationFile.create

method

configs/conf-{file}

Params

  • stanzaName - String

    A name for this stanza

  • values - Object

    A dictionary of key-value pairs to put in this stanza

  • callback - Function

    A callback with the created stanza: (err, createdStanza)

Create a stanza in this configuration file

Example

 var file = service.configurations().item("props");
 file.create("my_stanza", function(err, newStanza) {
     console.log("CREATED");
 });

Source (lib/client.js:1629)

create: function(stanzaName, values, callback) {
        if (utils.isFunction(values) && !callback) {
            callback = values;
            values = {};
        }
        
        values = values || {};
        values["name"] = stanzaName;
        
        this._super(values, callback);
    }
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.ConfigurationStanza

extends Splunk.Client.Entity

Splunk.Client.ConfigurationStanza

Represents a specific Splunk stanza. You can update and remove this stanza.

init

Splunk.Client.ConfigurationStanza.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • name - String

    The name of the index

Returns

Splunk.Client.ConfigurationStanza A Splunk.Client.ConfigurationStanza instance

Constructor for Splunk.Client.ConfigurationStanza

Source (lib/client.js:1663)

init: function(service, file, name) {
        this.name = name;
        this._super(service, Paths.configurations + "/conf-" + encodeURIComponent(file) + "/" + encodeURIComponent(name));
    } 
});

Inherited Methods

_load

Splunk.Client.Entity._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source

_load: function(properties) {
    properties = utils.isArray(properties) ? properties[0] : properties;
    
    this._super(properties);
},

refresh

Splunk.Client.Entity.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            that._load(response.odata.results);
            callback(null, that);
        }
    });
},

remove

Splunk.Client.Entity.remove

method

Params

  • callback - Function

    A callback when the object is deleted: (err)

Delete the entity

This will tell the server to delete this entity.

Source

remove: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.del("", {}, function() {
        callback();
    });
},

update

Splunk.Client.Entity.update

method

Params

  • props - Object

    Properties to be updated the object with.

  • callback - Function

    A callback when the object is updated: (err, entity)

Update the entity

This will update the entity on the server.

Source

update: function(props, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", props, function(err) {
            callback(err, that);
        });
        
        this._invalidate();
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Jobs

extends Splunk.Client.Collection

Splunk.Client.Jobs

Represents the Splunk collection of jobs. You can create and list search jobs using this container, or get a specific one.

init

Splunk.Client.Jobs.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

Returns

Splunk.Client.Jobs A Splunk.Client.Jobs instance

Constructor for Splunk.Client.Jobs

Source (lib/client.js:1689)

init: function(service) {
    this._super(service, Paths.jobs, {
        item: function(collection, props) {
            var sid = props.sid;
            return new root.Job(collection.service, sid);
        },
        isSame: function(entity, sid) {
            return entity.sid === sid;
        }
    });
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this.create     = utils.bind(this, this.create);
},

create

Splunk.Client.Jobs.create

method

search/jobs

Params

  • query - String

    The search query

  • params - Object

    A dictionary of properties for the job.

  • callback - Function

    A callback with the created job: (err, createdJob)

Create an asyncronous search job

Source (lib/client.js:1716)

create: function(query, params, callback) {
    callback = callback || function() {};
    params = params || {};
    params.search = query; 
    
    if ((params.exec_mode || "").toLowerCase() === "oneshot") {
        throw new Error("Please use Splunk.Client.Jobs.oneshotSearch for exec_mode=oneshot");
    }
    
    if (!params.search) {
        callback("Must provide a query to create a search job");
    } 
    var that = this;
    this.post("", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._invalidate();
            var job = new root.Job(that.service, response.odata.results.sid);
            callback(null, job);
        }
    });
},

oneshotSearch

Splunk.Client.Jobs.oneshotSearch

method

search/jobs

Params

  • query - String

    The search query

  • params - Object

    A dictionary of properties for the job.

  • callback - Function

    A callback with the results of the job: (err, results)

Create a oneshot search job

Create a oneshot search job using the specified query and parameters.

Example

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

Source (lib/client.js:1787)

oneshotSearch: function(query, params, callback) {
        callback = callback || function() {};
        params = params || {};
        params.search = query; 
        params.exec_mode = "oneshot";
        
        if (!params.search) {
            callback("Must provide a query to create a search job");
        } 
        var that = this;
        this.post("", params, function(err, response) {
            if (err) {
                callback(err);
            }
            else {
                callback(null, response.odata.results);
            }
        });
    }
});

Inherited Methods

refresh

Splunk.Client.Collection.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    that.get("", {count: 0}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            that._load(response.odata);
            callback(null, that);
        }
    });
},

item

Splunk.Client.Collection.item

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with the specified entity: (err, resource)

Fetch a specific entity.

Return a specific entity given its name. This will fetch the list of entities from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.item("search", function(err, app) {
     console.log(app.properties());
 })

Source

item: function(name, callback) {
    callback = callback || function() {};
    var that = this;
    this._validate(function(err) {
        if (err) {
            callback(err);
        } 
        else {            
            if (that._entitiesByName.hasOwnProperty(name)) {
                callback(null, that._entitiesByName[name]);
            }  
            else {
                callback(new Error("No entity with name: " + name));
            }
        }
    });
},

list

Splunk.Client.Collection.list

method

Params

  • callback - Function

    A callback with the list of entities: (err, list)

Retrieve a list of all entities in the collection

Return the list of all the entities in this collection, fetching them from the server if the collection is not in a valid state.

Example

 var apps = service.apps();
 apps.list(function(err, appList) {
     console.log(appList.length);
 });

Source

list: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this._validate(function(err) {
        callback(err, that._entities);
    });
},

contains

Splunk.Client.Collection.contains

method

Params

  • name - String

    The name of the entity to retrieve

  • callback - Function

    A callback with whether the entity was found: (err, wasFound, entity)

Check whether a specific entity exists

Check to see if the collection contains a specific entity, and if so, return that entity.

Example

 var apps = service.apps();
 apps.contains("search", function(err, found, searchApp) {
     console.log("Search App Found: " + found);
 });

Source

contains: function(id, callback) {
        callback = callback || function() {};
        var that = this;
        this.list(function(err, list) {
            if (err) {
                callback(err);
            }
            else {
                list = list || [];
                var found = false;
                var foundEntity = null;
                for(var i = 0; i < list.length; i++) {
                    // If the job is the same, then call the callback,
                    // and return
                    var entity = list[i];
                    if (that._isSame(entity, id)) {
                        found = true;
                        foundEntity = entity;
                        break;
                    }
                }
                
                // If we didn't find anything, let the callback now.
                callback(null, found, foundEntity);
            }
        });
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});

Splunk.Client.Job

extends Splunk.Client.Entity

Splunk.Client.Job

Represents a specific Splunk search job. You can perform various operations on this job, such as reading its status, cancelling it, getting results and so on.

init

Splunk.Client.Job.init

constructor

Params

  • service - Splunk.Client.Service

    A service instance

  • sid - String

    The search ID for this search

Returns

Splunk.Client.Job A Splunk.Client.Job instance

Constructor for Splunk.Client.Job

Source (lib/client.js:1831)

init: function(service, sid) {
    this._super(service, Paths.jobs + "/" + sid);
    this.sid = sid;
    // We perform the bindings so that every function works 
    // properly when it is passed as a callback.
    this.cancel         = utils.bind(this, this.cancel);
    this.disablePreview = utils.bind(this, this.disablePreview);
    this.enablePreview  = utils.bind(this, this.enablePreview);
    this.events         = utils.bind(this, this.events);
    this.finalize       = utils.bind(this, this.finalize);
    this.pause          = utils.bind(this, this.pause);
    this.preview        = utils.bind(this, this.preview);
    this.results        = utils.bind(this, this.results);
    this.searchlog      = utils.bind(this, this.searchlog);
    this.setPriority    = utils.bind(this, this.setPriority);
    this.setTTL         = utils.bind(this, this.setTTL);
    this.summary        = utils.bind(this, this.summary);
    this.timeline       = utils.bind(this, this.timeline);
    this.touch          = utils.bind(this, this.touch);
    this.unpause        = utils.bind(this, this.unpause);
},

cancel

Splunk.Client.Job.cancel

method

search/jobs/{search_id}/control

Params

  • callback - Function

    A callback when the search is done: (err)

Cancel a search job

Example

 var job = service.jobs().item("mysid");
 job.cancel(function(err) {
     console.log("CANCELLED");
 });

Source (lib/client.js:1869)

cancel: function(callback) {
    this.post("control", {action: "cancel"}, callback);
    this._invalidate();
},

disablePreview

Splunk.Client.Job.disablePreview

method

search/jobs/{search_id}/control

Params

  • callback - Function

    A callback with the this job: (err, job)

Disable preview for a job

Example

 var job = service.jobs().item("mysid");
 job.disablePreview(function(err, job) {
     console.log("PREVIEW DISABLED");
 });

Source (lib/client.js:1889)

disablePreview: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("control", {action: "disablepreview"}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

enablePreview

Splunk.Client.Job.enablePreview

method

search/jobs/{search_id}/control

Params

  • callback - Function

    A callback with the this job: (err, job)

Enable preview for a job

Example

 var job = service.jobs().item("mysid");
 job.disablePreview(function(err, job) {
     console.log("PREVIEW ENABLED");
 });

Source (lib/client.js:1914)

enablePreview: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("control", {action: "enablepreview"}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

events

Splunk.Client.Job.events

method

search/jobs/{search_id}/events

Params

  • params - Object

    Parameters for event fetching

  • callback - Function

    A callback with when the events are fetched: (err, events, job)

Get job events

Get the events for a job with given parameters.

Example

 var job = service.jobs().item("mysid");
 job.events({count: 10}, function(err, events, job) {
     console.log("Fields: ", events.fields);
 });

Source (lib/client.js:1942)

events: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("events", params, function(err, response) { 
        if (err) {
            callback(err);
        }
        else {
            callback(null, response.odata.results, that); 
        }
    });
},

finalize

Splunk.Client.Job.finalize

method

search/jobs/{search_id}/control

Params

  • callback - Function

    A callback with the this job: (err, job)

Finalize a search job

Example

 var job = service.jobs().item("mysid");
 job.finalize(function(err, job) {
     console.log("JOB FINALIZED");
 });

Source (lib/client.js:1971)

finalize: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("control", {action: "finalize"}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

pause

Splunk.Client.Job.pause

method

search/jobs/{search_id}/control

Params

  • callback - Function

    A callback with the this job: (err, job)

Pause a search job

Example

 var job = service.jobs().item("mysid");
 job.pause(function(err, job) {
     console.log("JOB PAUSED");
 });

Source (lib/client.js:1996)

pause: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("control", {action: "pause"}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

preview

Splunk.Client.Job.preview

method

search/jobs/{search_id}/results_preview

Params

  • params - Object

    Parameters for results preview fetching

  • callback - Function

    A callback with when the preview results are fetched: (err, results, job)

Get the preview results for a job

Get the preview results for a job with given parameters.

Example

 var job = service.jobs().item("mysid");
 job.preview({count: 10}, function(err, results, job) {
     console.log("Fields: ", results.fields);
 });

Source (lib/client.js:2024)

preview: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("results_preview", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            callback(null, response.odata.results, that);
        }
    });
},

results

Splunk.Client.Job.results

method

search/jobs/{search_id}/results

Params

  • params - Object

    Parameters for results fetching

  • callback - Function

    A callback with when the results are fetched: (err, results, job)

Get job results

Get the results for a job with given parameters.

Example

 var job = service.jobs().item("mysid");
 job.results({count: 10}, function(err, results, job) {
     console.log("Fields: ", results.results);
 });

Source (lib/client.js:2056)

results: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("results", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            callback(null, response.odata.results, that);
        }
    });
},

searchlog

Splunk.Client.Job.searchlog

method

search/jobs/{search_id}/search.log

Params

  • callback - Function

    A callback with the searchlog and job: (err, searchlog, job)

Get the search log for this job.

Example

 var job = service.jobs().item("mysid");
 job.searchlog(function(err, searchlog, job) {
     console.log(searchlog);
 });

Source (lib/client.js:2085)

searchlog: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("search.log", {}, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            callback(null, response.odata.results.log, that);
        }
    });
},

setPriority

Splunk.Client.Job.setPriority

method

search/jobs/{search_id}/control

Params

  • value - Number

    Value for the new priority

  • callback - Function

    A callback with the this job: (err, job)

Set the job priority

Example

 var job = service.jobs().item("mysid");
 job.setPriority(6, function(err, job) {
     console.log("JOB PRIORITY SET");
 });

Source (lib/client.js:2115)

setPriority: function(value, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("control", {action: "setpriority", priority: value}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

setTTL

Splunk.Client.Job.setTTL

method

search/jobs/{search_id}/control

Params

  • value - Number

    Value for the new priority

  • callback - Function

    A callback with the this job: (err, job)

Set the job TTL

Example

 var job = service.jobs().item("mysid");
 job.setTTL(1000, function(err, job) {
     console.log("JOB TTL SET");
 });

Source (lib/client.js:2141)

setTTL: function(value, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("control", {action: "setttl", ttl: value}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

summary

Splunk.Client.Job.summary

method

search/jobs/{search_id}/summmary

Params

  • params - Object

    Parameters for summary fetching

  • callback - Function

    A callback with with the summary and this job: (err, summary, job)

Get the summary for this job

Get the job summary for this job with the given parameters

Example

 var job = service.jobs().item("mysid");
 job.summary({top_count: 5}, function(err, summary, job) {
     console.log("Summary: ", summary);
 });

Source (lib/client.js:2169)

summary: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("summary", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            callback(null, response.odata.results, that);
        }
    });
},

timeline

Splunk.Client.Job.timeline

method

search/jobs/{search_id}/timeline

Params

  • params - Object

    Parameters for timeline fetching

  • callback - Function

    A callback with with the timeline and this job: (err, timeline, job)

Get the timeline for this job

Example

 var job = service.jobs().item("mysid");
 job.timeline({time_format: "%c"}, function(err, job, timeline) {
     console.log("Timeline: ", timeline);
 });

Source (lib/client.js:2199)

timeline: function(params, callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("timeline", params, function(err, response) {
        if (err) {
            callback(err);
        }
        else {
            callback(null, response.odata.results, that);
        }
    });
},

touch

Splunk.Client.Job.touch

method

search/jobs/{search_id}/control

Params

  • callback - Function

    A callback with this job: (err, job)

Touch a job

Example

 var job = service.jobs().item("mysid");
 job.touch(function(err) {
     console.log("JOB TOUCHED");
 });

Source (lib/client.js:2228)

touch: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.post("control", {action: "touch"}, function(err) {
        callback(err, that);
    });
    this._invalidate();
},

unpause

Splunk.Client.Job.unpause

method

search/jobs/{search_id}/control

Params

  • callback - Function

    A callback with this job: (err, job)

Unpause a search job

Example

 var job = service.jobs().item("mysid");
 job.unpause(function(err) {
     console.log("JOB UNPAUSED");
 });

Source (lib/client.js:2253)

unpause: function(callback) {
            callback = callback || function() {};
            
            var that = this;
            this.post("control", {action: "unpause"}, function(err) {
                callback(err, that);
            });
            this._invalidate();
        }
    });
})();

Inherited Methods

_load

Splunk.Client.Entity._load

method

Params

  • properties - Object

    The properties for this resource

Load the resource and mark it as valid, also storing the properties.

Source

_load: function(properties) {
    properties = utils.isArray(properties) ? properties[0] : properties;
    
    this._super(properties);
},

refresh

Splunk.Client.Entity.refresh

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Unconditionally refresh the resource

This will unconditionally refresh the object from the server and load it up, regardless of whether it is valid or not.

Source

refresh: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.get("", {}, function(err, response) {
        if (err) {
            callback(err);
        } 
        else {
            that._load(response.odata.results);
            callback(null, that);
        }
    });
},

remove

Splunk.Client.Entity.remove

method

Params

  • callback - Function

    A callback when the object is deleted: (err)

Delete the entity

This will tell the server to delete this entity.

Source

remove: function(callback) {
    callback = callback || function() {};
    
    var that = this;
    this.del("", {}, function() {
        callback();
    });
},

update

Splunk.Client.Entity.update

method

Params

  • props - Object

    Properties to be updated the object with.

  • callback - Function

    A callback when the object is updated: (err, entity)

Update the entity

This will update the entity on the server.

Source

update: function(props, callback) {
        callback = callback || function() {};
        
        var that = this;
        this.post("", props, function(err) {
            callback(err, that);
        });
        
        this._invalidate();
    }
});

isValid

Splunk.Client.Resource.isValid

method

Returns

Boolean Is this resource valid

Check whether the resource is in a valid state.

Source

isValid: function() {
    return this._maybeValid;
},

properties

Splunk.Client.Resource.properties

method

Returns

Object The properties for this resource

Retrieve the properties for this resource

This will retrieve the current properties for this resource, whether or not they are valid.

Source

properties: function(callback) {
    return this._properties;
},

read

Splunk.Client.Resource.read

method

Params

  • callback - Function

    A callback when the object is valid: (err, resource)

Conditionally refresh the resource

This will conditionally refresh the object from the server, only if it is not in a valid state.

Source

read: function(callback) {
        callback = callback || function() {};
        
        var that = this;
        this._validate(function(err) {
            callback(err, that);
        });
    }
});

get

Splunk.Client.Endpoint.get

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});

Source

get: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.get(
        url,
        params,
        callback
    );
},

post

Splunk.Client.Endpoint.post

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456/control
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});

Source

post: function(relpath, params, callback) {
    var url = this.path;
    // If we have a relative path, we will append it with a preceding
    // slash.
    if (relpath) {
        url = url + "/" + relpath;    
    }
    this.service.post(
        url,
        params,
        callback
    );
},

del

Splunk.Client.Endpoint.del

method

Params

  • 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: (err, response)

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.

Example

 // Will make a request to {service.prefix}/search/jobs/123456
 var endpoint = new Splunk.Client.Endpoint(service, "search/jobs/12345");
 endpoint.delete("", {}, function() { console.log("DELETED"))});

Source

del: function(relpath, params, callback) {
        var url = this.path;
        // If we have a relative path, we will append it with a preceding
        // slash.
        if (relpath) {
            url = url + "/" + relpath;    
        }
        this.service.del(
            url,
            params,
            callback
        );
    }
});