Splunk® Enterprise

Module System Reference

Acrobat logo Download manual as PDF


Splunk Enterprise version 7.2 is no longer supported as of April 30, 2021. See the Splunk Software Support Policy for details. For information about upgrading to a supported version, see How to upgrade Splunk Enterprise.
This documentation does not apply to the most recent version of Splunk® Enterprise. For documentation on the most recent version, go to the latest release.
Acrobat logo Download topic as PDF

BaseController

conf()

Note: Beginning with Splunk version 4.2, use the Model API (class SplunkAppObjModel), instead, to work with Splunk configuration objects.

Get a configuration key from the Splunk configuration.

Synopsis

value = conf( key, name, stanza, cast, default )

Parameters

key   Configuration entity key value.
name String Default: web
stanza String Default: settings
cast   Default: None
default   Default: None

Return Value

Integer Configuration key.

Raises

KeyError Specified key does not exist. Your configuration may be corrupt or may require a restart.

make_route()

The make_route() method is a wrapper, returning a URL path for a given route. The method returns a URL path for the specified, base_path, route.

Synopsis

route = make_route( base_path, **kwargs)

Parameters

base_path String Route
kwargs Object Name-value pair, list of tuples, or dictionary query string.

Return Value

String Relative URL for the specified base_path .

Examples

Example 1

make_route('/search/jobs', job_id=1234, action=delete)

Example 2

make_route('/search/jobs', job_id=1234, action=delete, _qs=[('q', 'search val to quote')])

Example 3

make_route('/search/jobs', job_id=1234, action=delete, _qs=dict(q='search val to quote'))

See Also

make_url()

make_url()

The make_url() method extends the specified path relative to the current app server location, specifying a full path or a series of arguments representing path segments.

Synopsis

results = Splunk.util.make_url(path)

path String Relative path to extend, or path segment arguments.

Return Value

String Qualified relative path.

Example

Full path argument

var path1 = Splunk.util.make_url('/static/foo.js'); alert(path1);

Path segment arguments

var path2 = Splunk.util.make_url('app', 'search', 'flashtimeline') alert(path2);

Common application

Load the myContent.html file located in the /appserver/static directory of the current app.

<div id="sampleContent"></div>

<script>

   var url = Splunk.util.make_url('/static/app/' + Splunk.util.getCurrentApp() + '/myContent.html');
   $("#sampleContent").load(url);

</script>

The example loads the content of myContent.html into the sampleContent DIV. We recommend using the getCurrentApp() utility for portability.

See Also

make_full_url()

push_version()

The push_version() method is a wrapper, forcing a version increment on application server static assets and browsers to update cached static content.

The returned version is a local-to-installed-instance version number used in combination with the build number to specify a revision of static resources in $SPLUNK_HOME/etc/apps/<app>/appserver/static . This number should be incremented by a POST to /_bump whenever a static resource has been changed to force the client to fetch the new resource regardless of the Expires headers that were sent with it.

Synopsis

version = push_version()

Return Value

Integer Incremented version number.

Example

return "Version bumped to %i" % self.push_version()

redirect_to_route()

The redirect_to_route() method is a convenience method, wrapping a call to cherrypy.HTTPRedirect() with the URI provided by make_route().

Synopsis

redirect_to_route( *target, **kwargs )

Parameters

target String Redirection target.
kwargs Object [OPTIONAL] keyword-value pair dictionary representing the query string to include with redirection.

Return Value

Undefined

Raises

cherrypy.HTTPRedirect(self.make_route( *target, **kwargs))

Example

self.redirect_to_route('/accounts',

                      username='someUser',
                      action='delete',
                     _qs=[ ('return_to', '/') ])

See Also

make_route()
redirect_to_url()
render_template()
cherrypy.HTTPRedirect()

redirect_to_url()

The redirect_to_url() method is a convenience method, wrapping a call to cherrypy.HTTPRedirect() with the redirect URI.

Synopsis

redirect_to_url( *target, **kwargs)

Parameters

target String Redirection target.
kwargs Object [OPTIONAL] keyword-value pair dictionary representing the query string to include with redirection.

Return Value

Undefined

Raises

cherrypy.HTTPRedirect(self.make_url( *target, **kwargs))

Example

self.redirect_to_url('/api/search/jobs', job_id=1234)

See Also

render_template()
redirect_to_route()
cherrypy.HTTPRedirect()

render_json()

The render_json() method returns JSON-formatted response data.

Synopsis

response = render_json( response_data, set_mime)

Parameters

response_data String Data to return. If not JSON data, the data are parsed into JSON format.
set_mime String [OPTIONAL] Mime type specified in the response. Default: 'text/json'

Return Value

String JSON-formatted response_data with 256 bytes whitespace padding.

Exceptions

TBD

Examples

Example 1

output = {'foo': 'bar', 'fiz' : {'foobar': 1, 'fizbaz': 2 } }

self.render_json(output)

Example 2

self.render_json({'status': 'FIELD_ERRORS', 'fields': { key: 'Password error' },},

                set_mime='text/html')

See Also

render_template()

render_template()

The render_template() method renders the specified Mako template. First, the method creates a global instantiation of TemplateLookup named mako_lookup() by calling setup_mako(). The specified template, template_name, must exist within the lookup instance to be rendered. Template arguments, template_args, are passed to the template to be rendered.

Synopsis

response = render_template( template_name, template_args)

Parameters

template_name String Mako template to be rendered.
template_args Objects [OPTIONAL] Dictionary of arguments passed to template_name.

Return Value

String Rendered template.

Raises

Exception 'unable to obtain template=%s' % template_name

See Also

render_json()
TemplateLookup
setup_mako()

setup_mako()

Initializes an instance of TemplateLookup. In general, this method is called by render_template() and does not need to be called, explicitly. However, setup_mako() can be overridden to provide additional lookup paths, imports, or other options, which can be retrieved by calling mako_lookup().

Synopsis

setup_mako()

Parameters

None

Return Value

Undefined

See Also

render_template()
TemplateLookup

strip_url()

The strip_url() method returns a specified URL without the root endpoint or i18n prefixes. Use this method to format a URL path fragment to pass to methods such as make_url(), which can safely handle the root endpoint and i18n prefixes on a per user basis.

The path parameter is a URL, and the method returns a URL with the root endpoint and i18n prefixes stripped.

Synopsis

url = strip_url( path )

Parameters

path String URL to be stripped.

Return Value

String The path URL with the root endpoint and i18n prefixes stripped.

See Also

make_url()

Last modified on 12 August, 2019
PREVIOUS
ModuleHandler
  NEXT
SplunkRESTModel

This documentation applies to the following versions of Splunk® Enterprise: 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.0.4, 7.0.5, 7.0.6, 7.0.7, 7.0.8, 7.0.9, 7.0.10, 7.0.11, 7.0.13, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9, 7.1.10, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 7.2.10, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.3.6, 7.3.7, 7.3.8, 7.3.9


Was this documentation topic helpful?


You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters