Skip to main content
Sumo Logic

Filter with template variables

Template variables are a feature of Sumo Logic Dashboard (Beta) that allow you to analyze specific data on demand. They give you the ability to filter the data displayed on your dashboard so you can quickly troubleshoot a problem. Queries can be changed on the fly by choosing values for variables from drop-down lists without having to manually edit queries.

Create a template variable

There are three types of template variables you can use as a dashboard filter:

Adding a Custom List variable

A custom list variable allows you to specify random string values for a variable. These are helpful when you know the values of fields you want to reference on-the-fly. For example, if your data had a field named color and you knew the potential values you wanted to reference were redgreen, and purple. A custom list variable would be assigned the Variable Name color and the Custom List would be given the value red, green, purple. Then in your panel query you would provide the variable as {{color}}. With these set up you can use the variable to filter your data by color.

To add a Custom List variable to a dashboard, do the following:

  1. In the Dashboard (Beta) top menu bar, click the plus (+) sign. The Add Template Variable panel appears.

TV_Add+_Variable.png

  1. In the Add Template Variable panel, enter a unique Variable Name
  1. Select Custom List as the Data Source.
  2. Enter a Custom List of variables in the text field that will be used as dashboard values. 

custom list variable.png

  1. Optional: Enter or select a Default Value for the variable. The default value is always applied first.
  2. Optional: Toggle ON the Include ALL Option to include a wildcard asterisk (*) in the available options.
  3. Click Add Template Variable to apply the variable to the dashboard.

TV_Add_Template_Variable.png 

Adding a Metadata Search variable

A Metadata Search variable allows you to specify a metadata field to act as a variable. You'll be able to select from previously parsed values assigned to the field as your filter.

To add a Metadata Search variable to a dashboard, do the following:

  1. In the Dashboard (Beta) top menu bar, click the plus (+) sign. The Add Template Variable panel appears.

TV_Add+_Variable.png

  1. In the Add Template Variable panel, enter a unique Variable Name.
  1. Select Metadata Search as the Data Source.
  2. The Filter input allows you to filter the scope of your data before choosing the field you want to use. Click in the Filter input, begin typing, and choose a filter from the pop-up list. A list of valid values appears. Select a value for the filter, and add other filters as needed.

TV_MetadataSearch_filter.png

  1. The Key input is where you select the metadata field you want to use as the filter. Click in the Key input and begin typing. Select a valid option from the pop-up list.

TV_MetadataSearch_Key.png 

  1. Optional: Click in the Default Value field, and a list of valid variables appears in the panel on the right. Select an appropriate variable from the list. The default value is always applied first.

TV_MetadataSearch_DefaultValue.png

  1. Optional: Toggle ON the Include ALL Option to include a wildcard asterisk (*) in the available options.
  2. Click Add Template Variable to apply the variable to the dashboard.

TV_Add_Template_Variable.png

Adding a Logs Search variable

To add a Logs Search variable to a dashboard, do the following:

  1. In the Dashboard (Beta) top menu bar, click the plus (+) sign. The Add Template Variable panel appears.

TV_Add+_Variable.png

  1. In the Add Template Variable panel, enter a unique Variable Name
  1. Select Logs Search as the Data Source.
  1. Click in the Query field and begin typing your query. Select valid options from the pop-up list as they appear until your query is complete.

TV_LogsSearch_Query.png

  1. Click in the Key field, begin typing and select valid options from the pop-up list.

TV_LogsSearch_Key.png

  1. Optional: Click in the Default Value field and enter a value, or select a valid variable from the list on the right.

TV_LogsSearch_DefaultValue.png

  1. Optional: Toggle ON the Include ALL Option to include a wildcard asterisk (*) in the available options.
  2. Click Add Template Variable to apply the variable to the dashboard.

TV_Add_Template_Variable.png

Editing a template variable

This task shows you how to modify an existing template variable in a Dashboard (Beta) so you can rescope your data on the fly. This is helpful for troubleshooting a problem to a fast resolution to the root cause.

To edit a template variable, do the following:

  1. Hover the cursor over the end of the template variable field to display the Details icon.

TV_Edit_select_Edit1.png

  1. Click the Details icon and select Edit from the drop-down menu. The Edit Variable dialog appears.

TV_Edit_select_Edit2.png

  1. Perform steps 2 through 4 in Adding a template variable.
  2. Click Apply and view the resulting data transformations on the dashboard.

Deleting a template variable

This task shows you how you can easily delete a template variable from Dashboard (Beta).

To delete a template variable, do the following:

  1. Hover the cursor over the end of the template variable field to display the Details icon.

TV_Edit_select_Edit1.png

  1. Click the Details icon and select Delete from the drop-down menu. The variable along with the resulting data transformations are automatically removed from the dashboard.

TV_Edit_select_Delete.png

Example: Using variables in queries

Logs and metrics variables allow you to interject metadata into your queries. This section shows you how to use a variable you created in a query.  

How to use a logs variable in a query

To use a variable in a logs query, do the following:

  1. Locate the name of the variable you'd like to use in the drop-down list and copy it.
  2. Go to your logs query and insert {{ var_name }} in the query, substituting var_name with the actual name of the variable, as shown in the following example with our {{cluster}} logs variable.

Logs_variable_query_example.png

At run time, the value inside the curly braces is replaced with the value of the variable you specified (from the variable drop-down list). 

How to use a metrics variable in a query

To use a metrics variable in a query working with the structured query builder, do the following:

  1. In the structured query builder, enter the Key for the variable followed by an equals sign.
  2. Select the desired variable from the drop-down list. It appears in curly braces to indicate it is a variable.

Metrics_variable_query_example1.png

The variable is inserted into the query and will convert the variable into the appropriate value, as shown in the following example.

Metrics_variable_query_example2.png

To use a metrics variable in a query working in advanced query mode, do the following:

  1. Locate the name of the variable you'd like to use in the drop-down list and copy it.
  2. Go to your metrics query and insert {{ var_name }} in the query, substituting var_name with the actual name of the variable.