Splunk® Enterprise

Dashboards and Visualizations

Download manual as PDF

Download topic as PDF

Form examples

A form is similar to a dashboard, but provides an interface for users to supply values to one or more search terms, typically using text boxes, dropdown menus, or radio buttons. A form shields users from the details of the underlying search – it allows users to focus only on the terms for which they are searching and the results. The results can be displayed in tables, event listings, or any of the visualizations available to dashboards.

This topic contains basic examples that show how to create forms. Refer to the Splunk 6.x Dashboard Examples app for additional examples that use more robust source data. The examples show how to use tokens to pass values in forms. See Token usage in dashboards for details on token implementation.

Basic form example

The user input to a form defines tokens for the selected values of the input. A search in the form uses the tokens to specify the values to use in the search. The search accesses the value for the token using the '$...$' as a delimiter for the token value.

For example, the following code snippet defines a dropdown that uses the sourcetype_tok token to represent the selection by the user. It also defines the choices for the dropdown.

   <input type="dropdown" token="sourcetype_tok">
     <label>Select a source type</label>
     <default>splunkd</default>
     <choice value="splunkd">splunkd</choice>
     <choice value="splunk_web_access">splunk_web_access</choice>
     <choice value="splunkd_ui_access">splunkd_ui_access</choice>
   </input>

The search in the form references the token. In the following code snippet, $sourcetype_tok$ represents the value from the dropdown choice.

       <search>
         <query>
           index = _internal sourcetype=$sourcetype_tok$ 
           | timechart count by sourcetype
         </query>
           <earliest>-7d</earliest>
           <latest>-0d</latest>
       </search>


Viz form example.png


Here is the simple XML implementing the form.

<form>
  <label>Form example: source type time chart</label>

  <!--autoRun means the search runs as soon as it is loaded. -->
  <!-- Do not need a submit button                           -->
  <fieldset autoRun="true" submitButton="false">
    <input type="dropdown" token="sourcetype_tok">
      <label>Select a source type</label>
      <default>splunkd</default>
      <choice value="splunkd">splunkd</choice>
      <choice value="splunk_web_access">splunk_web_access</choice>
      <choice value="splunkd_ui_access">splunkd_ui_access</choice>
    </input>
  </fieldset>

  <row>
    <panel>
      <chart>
        <search>
          <query>
            index = _internal sourcetype=$sourcetype_tok$ 
            | timechart count by sourcetype
          </query>
            <earliest>-7d</earliest>
            <latest>-0d</latest>
        </search>
      </chart>
    </panel>
  </row>
</form>

Form with time inputs example

You can add one or more time inputs to a form. If you add a single time input, a token for the time input is not necessary. The time input drives the data for all searches in the form.

However if you add additional time inputs to a form, specify a token for each time input. The searches in the form reference the tokens to indicate which time input to use.

The following code snippet creates a time input that defines a token for local use.

     <input type="time" token="time_tok" searchWhenChanged="true">
       <label></label>
       <default>
         <earliest>-24h@h</earliest>
         <latest>now</latest>
       </default>
     </input>

Use the earliest and latest modifiers to the time input token when accessing the local time input.

       <search>
         <query>
           index=_internal sourcetype=$sourcetype_tok$ 
           | stats count as sourcetype</query>
         <earliest>$time_tok.earliest$</earliest>
         <latest>$time_tok.latest$</latest>
       </search>

The following example uses a global timer that drives the Source Type Timechart panel. The Source Type Event Counter panel contains a local time for that panel only.

Viz form time pickers.png

<form>
  <label>Form example: add time pickers</label>
  <fieldset autorun="true" submitButton="false">
    <input type="dropdown" token="sourcetype_tok">
      <label>Select a source type</label>
      <default>splunkd</default>
      <choice value="splunkd">splunkd</choice>
      <choice value="splunk_web_access">splunk_web_access</choice>
      <choice value="splunkd_ui_access">splunkd_ui_access</choice>
    </input>

    <!-- Global timer. Not token is necessary -->
    <input type="time" searchWhenChanged="true">
      <label>Select time range</label>
      <default>
        <earliest>-7d@h</earliest>
        <latest>now</latest>
      </default>
    </input>

  </fieldset>
  <row>
    <panel>
      <title>Source type time chart</title>
      <chart>
        <search>
          <query>index = _internal sourcetype=$sourcetype_tok$ 
            | timechart count by sourcetype</query>
        </search>
      </chart>
    </panel>
    <panel>
      <title>Source type event counter</title>

      <!-- Local timer. Use tokens to access selected time. -->
      <input type="time" token="time_tok" searchWhenChanged="true">
        <label></label>
        <default>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </default>
      </input>

      <single>
        <search>
          <query>
             index=_internal sourcetype=$sourcetype_tok$ 
             | stats count as sourcetype</query>

          <!-- Use the earliest and latest modifiers to the time input token -->
          <earliest>$time_tok.earliest$</earliest>
          <latest>$time_tok.latest$</latest>

        </search>
        <option name="beforeLabel">Found </option>
        <option name="afterLabel">$sourcetype_tok$ events</option>
      </single>
    </panel>
  </row>
</form>

Static and dynamic inputs to forms

The following form inputs require multiple choices for selection by the user. You can statically define the inputs or use a search to dynamically populate the inputs to a form.

  • Check box
  • Dropdown
  • Multiselect
  • Radio

The search in the following example compares static and dynamic definition for choices. The dropdown uses a populating search to define the choices.

  • Populating <search>
    Returns fields to use for the label and value of the choices.
  • <fieldForLabel> <fieldForValue>
    Child elements to the <input> element. These specify the fields to use to populate choices for the dropdown.


Viz populate search.png

<form>
  <label>Populate an input with a search</label>
  <description>Events Filtered by User and Sourcetype</description>
  <!-- Do not need a Search Button. Inputs search when changed -->
  
  <fieldset autoRun="true" submitButton="false">
    
    <!-- Static definition of choices -->
    <input type="radio" token="username_tok" searchWhenChanged="true">
      <label>Select a User:</label>
      
      <!-- Define the default value -->
      <default>All</default>

      <!-- Hard-code the choices -->
      <choice value="*">All</choice>
      <choice value="-">-</choice>
      <choice value="admin">Admin</choice>
      <choice value="nobody">Nobody</choice>
      <choice value="splunk-system-user">Splunk System User</choice>
    </input>
    
    <!-- Dynamic definition of choices -->
    <input type="dropdown" token="sourcetype_tok" searchWhenChanged="true">
      <label>Select a Sourcetype:</label>
      <prefix>sourcetype="</prefix>
      <suffix>"</suffix>
      
      <!-- Define the default value -->
      <default>splunkd</default>
      
      <!-- Hard-code the choice for "All" -->
      <choice value="*">All</choice>
      
      <!-- Define the other choices with a populating search -->
      <search>
        <query>
          index=_internal | stats count by sourcetype
        </query>
      </search>
      <fieldForLabel>sourcetype</fieldForLabel>
      <fieldForValue>sourcetype</fieldForValue>
    </input>
    
  </fieldset>
  <row>
    <panel>
      <!-- Use tokens from the <input> elements in the panel title -->
      <title>
        Input selections: (radio) "$username_tok$", (dropdown) $sourcetype_tok$
      </title>
      
      <chart>
        
        <!-- search for the visualization, references the input tokens-->
        <search>
          <query>
            index=_internal user=$username_tok$ $sourcetype_tok$ | timechart count
          </query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
       </chart>
      
    </panel>
  </row>
</form>

Create a form with a global search

You can create a form that uses a global search that drives the data in the various panels. This scenario is another form of post-process search. You should be careful about using post-process searches because of various limitations. In many cases, a post-process search is not always the most efficient way to use search resources. Read carefully the topic Post-process searches. It discusses Post-process limitations and other factors to consider before implementing a post-process search.

The following example shows a form with a global search.


Viz form global search.png


The global search uses a transforming search command to avoid the 10,000 event limit for the number of events that you can pass to a post-process search:

 <search id="global_search">
   <query>
     index=_internal source=*splunkd.log | stats count by component, log_level
   </query>
 </search>

The values for the dropdown choices contain the post-process searches:

 <fieldset autoRun="true" submitButton="false" searchWhenChanged="true">
   <input type="dropdown" token="stats_tok">
     <label>Select count by:</label>
     <default>Log level</default>
     <choice value="stats sum(count) AS count by log_level">Log level</choice>
     <choice value="search log_level=error | stats sum(count) AS count by component">Component</choice>
   </input>

The panel in the form accesses the selected choice using the token from the dropdown:

       <search base="global_search">
         <query>
           $stats_tok$
         </query>
       </search>

Here is the complete code for a form with a global search:

<form>

 <label>Form with global search</label>
 <search id="global_search">
   <query>
     index=_internal source=*splunkd.log | stats count by component, log_level
   </query>
 </search>
 
 <fieldset autoRun="true" submitButton="false" searchWhenChanged="true">
   <input type="dropdown" token="stats_tok">
     <label>Select count by:</label>
     <default>Log level</default>
     <choice value="stats sum(count) AS count by log_level">Log level</choice>
     <choice value="search log_level=error | stats sum(count) AS count by component">Component</choice>
   </input>
   
   <input type="time">
     <default>Last 7 days</default>
   </input>
 </fieldset>
 <row>
   <panel>
     <chart>
       <option name="charting.chart">bar</option>
       <search base="global_search">
         <query>
           $stats_tok$
         </query>
       </search>
     </chart>
   </panel>
 </row>
</form>
PREVIOUS
Dashboard examples
  NEXT
Using a third party XML editor

This documentation applies to the following versions of Splunk® Enterprise: 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.3.0, 6.3.1, 6.3.2, 6.3.3, 6.3.4, 6.3.5, 6.3.6, 6.3.7, 6.3.8, 6.3.9, 6.3.10, 6.3.11, 6.4.0, 6.4.1, 6.4.2, 6.4.3, 6.4.4, 6.4.5, 6.4.6, 6.4.7, 6.4.8, 6.5.0, 6.5.1, 6.5.1612 (Splunk Cloud only), 6.5.2, 6.5.3, 6.5.4, 6.5.5, 6.6.0, 6.6.1, 6.6.2


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