Skip to main content
Sumo Logic

Filter with template variables

Learn how to use template variables to dynamically filter dashboard data.

Template variables are a feature of Dashboard (Beta) that allows you to create dynamic dashboards that re-scope data on the fly. You can apply variables to troubleshoot a problem through your dashboard, and view the updated data in real time for a fast resolution to the root cause. This document shows you how to add a new template variable to a dashboard, and then how to edit or delete an existing template variable.

Adding a template variable

Template variables provide the ability for dynamically updating Dashboard (Beta). You can apply variables to a dashboard and re-factor the data being presented on-the-fly. In this task, you will learn how to create a new template variable and apply it to a dashboard.

To add a template variable, do the following:

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

TV_Add+_Variable.png

  1. In the Add Variable dialog, enter a unique Variable Name. Our example variable is called Appliance_Search.  
  1. Select a Data Source:
  • Custom List - a custom set of options
  • Metadata Search - metrics metadata based options 
  • Log Search - logs query based options
  1. Do one of the following:
  • For a Custom List, enter the variables with which you want to filter the dashboard and specify a Default Value. The Default Value is the current variable, and is only applied if there are no matches from the Custom List.

DB_Variable_Custom-List.png

  • For a Metadata Search, click in the Filter field and begin typing. Choose a variable and an associated value as they appear in the drop-down menus. Select all necessary variables, then specify a Key and Default Value. The Key is like a keystone in masonry, it's at the apex of all the variables, and is the value from which all other variables are filtered. The Default Value is the current variable, and is only applied if there are no matches.

 DB_Variable_Metadata-Search.png

  • For a Log Search, click in the Filter field and begin typing. Choose a variable and an associated value as they appear in the drop-down menus. Select all necessary variables, then specify a Key and Default Value. The Key is like a keystone in masonry, it's at the apex of all the variables, and is the value from which all other variables are filtered. The Default Value is the current variable, and is only applied if there are no matches.

DB_Variable_Logs-Search.png

  1. Click Apply.

TV_Add_Metadata-Search_Apply.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). 

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.