Splunk® Enterprise

Module System User Manual

Download manual as PDF

This documentation does not apply to the most recent version of Splunk. Click here for the latest version.
Download topic as PDF

Getting started example


is_visible = true
label = App Framework Tutorial
id = Dev_tutorial
author = Splunk, Inc.
description = App Framework Tutorial App
version = 1.0


<collection label="Examples">

   <view name="Example" />



<view template="dashboard.html">

   <label>Example: Using a Custom Module</label>
   <module name="AccountBar" layoutPanel="appHeader"/>
   <module name="AppBar" layoutPanel="navigationHeader"/>
   <module name="Message" layoutPanel="messaging">
       <param name="filter">*</param>
       <param name="clearOnJobDispatch">False</param>
       <param name="maxSize">1</param>

   <module name="StaticContentSample" layoutPanel="panel_row1_col1">
       <param name="text"><![CDATA[

<h1>Example: Using a Custom Module</h1> <p> This simple application searches the metrics log and lists the CPU utilization of each indexer stage, for the last seven days. </p> <p> Search string: <tt>index=_internal source=*metrics.log group=pipeline | stats sum(cpu_seconds) as totalCPU by name</tt> </p> <p> Results are displayed using a custom module, <tt>CustomResultsTable</tt>. </p> ]]>


       <module name="HiddenSearch" layoutPanel="panel_row2_col1" group="CPU Utilization" autoRun="True">
           <param name="search">index=_internal source=*metrics.log group=pipeline | stats sum(cpu_seconds) as totalCPU by name</param>
           <param name="earliest">-7d</param>
           <module name="CustomResultsTable">

</view> ]]>


className = Splunk.Module.CustomResultsTable
superClass = Splunk.Module.DispatchingModule
description = Custom module for App Framework example.


Splunk.Module.CustomResultsTable = $.klass(Splunk.Module.DispatchingModule, {

   initialize: function($super, container) {
       this.myParam = this.getParam("myParam");
       this.resultsContainer = this.container;

   onJobDone: function(event) {

   getResultParams: function($super) {
       var params = $super();
       var context = this.getContext();
       var search  = context.get("search");
       var sid         = search.job.getSearchId();

       if (!sid) this.logger.error(this.moduleType, "Search ID is missing.");

       params.sid = sid;
       return params;

   renderResults: function($super, htmlFragment) {
       if (!htmlFragment) {
           this.resultsContainer.html('No content available.');



import controllers.module as module
import splunk, splunk.search, splunk.util, splunk.entity
import lib.util as util
import lib.i18n as i18n
import logging

logger = logging.getLogger('splunk.module.CustomResultsTable')

import math
import cgi


class CustomResultsTable(module.ModuleHandler):

   def generateResults(self, host_app, client_app, sid, count=1000,
           offset=0, entity_name='results'):

       count = max(int(count), 0)
       offset = max(int(offset), 0)
       if not sid:
           raise Exception('CustomResultsTable.generateResults - sid not passed!')

           job = splunk.search.getJob(sid)
       except splunk.ResourceNotFound, e:
           logger.error('CustomResultsTable could not find the job %s. Exception: %s' % (sid, e))
           return _('<p class="resultStatusMessage">The job appears to have expired or has been canceled.</p>')
       output = []
       output.append('<div class="CustomResultsTableWrapper">')
       output.append('<table class="CustomResultsTable splTable">')
       fieldNames = [x for x in getattr(job, entity_name).fieldOrder if (not x.startswith('_'))]
       offset_start = offset
       if offset < 0 and count < abs(offset):
           offset_start = -count
       dataset = getattr(job, entity_name)[offset_start: offset+count]
       for i, result in enumerate(dataset):

           for field in fieldNames:
               fieldValues = result.get(field, None)
               if fieldValues:
                   renderedValues = [cgi.escape(x.value) for x in fieldValues[:MAX_MULTI_VALUE_COUNT]]
                   output.append('>%s</td>' % "".join(renderedValues))
       if (entity_name == 'results' and job.resultCount == 0):
           if job.isDone:
               output = self.generateStatusMessage(entity_name, 'nodata', job.id)
               output = self.generateStatusMessage(entity_name, 'waiting', job.id)
           output = ''.join(output)

       return output
Set up your app
Example 1 - Simple customizations

This documentation applies to the following versions of Splunk® Enterprise: 6.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 6.0.5, 6.0.6, 6.0.7, 6.0.8, 6.0.9, 6.0.10, 6.0.11, 6.0.12, 6.0.13, 6.0.14, 6.1, 6.1.1, 6.1.2, 6.1.3, 6.1.4, 6.1.5, 6.1.6, 6.1.7, 6.1.8, 6.1.9, 6.1.10, 6.1.11, 6.1.12, 6.1.13, 6.2.0, 6.2.1, 6.2.2, 6.2.3, 6.2.4, 6.2.5, 6.2.6, 6.2.7, 6.2.8, 6.2.9, 6.2.10, 6.2.11, 6.2.12, 6.2.13, 6.2.14, 6.2.15

Was this documentation topic helpful?

Enter your email address, and someone from the documentation team will respond to you:

Please provide your comments here. Ask a question or make a suggestion.

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