Example: Parameterized sensors

Overview of parameterized sensors

A parameterized sensor requires you to enter input (parameter values) before the sensor can collect results from endpoints. You enter the parameter values when issuing a dynamic question that uses the sensor. For example, when you issue a question with the File Size sensor, Interact prompts you to specify the name of the file for which the sensor collects size information. Tanium Cloud then creates an object called a temporary sensor, which contains the substituted parameter values. Tanium Cloud uses the temporary sensor in the question that it sends to Tanium Clients. The Clients then run the sensor to return an answer.

For more information about entering parameter values when issuing questions and about saving questions with parameterized sensors, see Questions with parameterized sensors.

To create a parameterized sensor, configure the Scripts and Parameter Inputs as described in the following sections when you perform the steps in Create a sensor:

Note: Sensor write permission is required to create, edit, or delete sensors. Tanium reserves this permission for customers who have completed a Tanium Custom Content training course. Contact Tanium Support to gain access to this course and the Sensor write permission. For more information, see Contact Tanium Support.
Important: Before saving a question with a parameterized sensor, see Questions with parameterized sensors.

Sample question with parameterized sensor

File System Permissions is a Tanium-provided parameterized sensor. When you use that sensor in a dynamic question, Interact prompts you to specify values for the parameters File or Folder Path and Acknowledgement.

Figure 1. Dynamic question with parameterized sensor
Parameterized sensor

After you enter values and click Ask Question, Tanium Cloud issues the question to Tanium Clients. When Clients return results, the Question Results page shows the question with the values that you entered and the grid shows the results.

Figure 2. Parameterized sensor results
Parameterized sensor results

For more examples of questions with parameterized sensors, see Questions with parameterized sensors.

Script for a parameterized sensor

You add a sensor script in the sensor configuration page, as described in Create a sensor. The script for a parameterized sensor has the requirements described in Parameter names and UTF-8 encoding and decoding.

Note: In the script text, include validation for the parameter types List, Text Input, and Text Area. For more information, see Validation expressions.

Parameter names

In the script for a parameterized sensor, enclose input parameters with double vertical bars (||<parameter>||), such as ||Acknowledgement|| and ||Path|| in the following example of a PowerShell sensor. You must specify the same parameter names when you configure the Key field for Parameter Inputs in the sensor configuration, as described in Configure parameter inputs for a sensor.

Figure 3. Example: sensor parameters in PowerShell script
PowerShell example of sensor script
Figure 4. Example: sensor parameters in VBScript script
VBScript example of sensor script

UTF-8 encoding and decoding

When you issue a question with a parameterized sensor, Tanium Cloud encodes the parameter values that you enter before passing the values to the sensor script. Tanium Cloud includes the encoded values in the temporary sensor that it sends in the question to Tanium Clients. Clients then run the script to answer the question, and the script applies UTF-8 decoding to the encoded values.

PowerShell sensor scripts use the .NET method [System.Uri]::UnescapeDataString() to decode UTF-8 encoded parameters. For example, the script for the sensor File System Permissions uses that method for the parameter File or Folder Path:

CODE
$ItemPath = [System.Uri]::UnescapeDataString("||Path||")

Many sensor scripts in VBScript use a function for UTF-8 decoding, such as the following example.

Figure 5. UTF-8 decode function
JAVASCRIPT
'========================================
' UTF8Decode
'========================================
' Used to convert the UTF-8 style parameters passed from 
' the server to sensors in sensor parameters.
' This function should be used to safely pass non english input to sensors.
'-----
'-----
Function UTF8Decode(str)
    Dim arraylist(), strLen, i, sT, val, depth, sR
    Dim arraysize
    arraysize = 0
    strLen = Len(str)
    for i = 1 to strLen
        sT = mid(str, i, 1)
        if sT = "%" then
            if i + 2 <= strLen then
                Redim Preserve arraylist(arraysize + 1)
                arraylist(arraysize) = cbyte("&H" & mid(str, i + 1, 2))
                arraysize = arraysize + 1
                i = i + 2
            end if
        else
            Redim Preserve arraylist(arraysize + 1)
            arraylist(arraysize) = asc(sT)
            arraysize = arraysize + 1
        end if
    next
    depth = 0
    for i = 0 to arraysize - 1
		Dim mybyte
        mybyte = arraylist(i)
        if mybyte and &h80 then
            if (mybyte and &h40) = 0 then
                if depth = 0 then
                    Err.Raise 5
                end if
                val = val * 2 ^ 6 + (mybyte and &h3f)
                depth = depth - 1
                if depth = 0 then
                    sR = sR & chrw(val)
                    val = 0
                end if
            elseif (mybyte and &h20) = 0 then
                if depth > 0 then Err.Raise 5
                val = mybyte and &h1f
                depth = 1
            elseif (mybyte and &h10) = 0 then
                if depth > 0 then Err.Raise 5
                val = mybyte and &h0f
                depth = 2
            else
                Err.Raise 5
            end if
        else
            if depth > 0 then Err.Raise 5
            sR = sR & chrw(mybyte)
        end if
    next
    if depth > 0 then Err.Raise 5
    UTF8Decode = sR
End Function

In shell scripts, you can use a function similar to the following percent_decode function to decode the parameter data.

Figure 6. percent_decode function
CODE
#!/bin/sh

percent_decode() {
        local data=$(echo "$1" | sed 's/%/\\\x/g')
        /usr/bin/printf '%b' "$data"
}

myVariable=`percent_decode "||parameter_value||"`

The printf utility might not be available or might not work correctly on all Linux, macOS, and UNIX platforms. The following implementation is more fool-proof but less elegant.

Figure 7. brute_force_percent_decode function
JSON
#!/bin/sh 

brute_force_percent_decode() {
        # decode everything between 0x20-0x7E except:
        #0 1 2 3 4 5 6 7 8 9 (0x30-0x39)
        #A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (0x41-0x5A)
        #a b c d e f g h i j k l m n o p q r s t u v w x y z (0x61-0x7A)
        echo "$1" | sed -e 's/%20/ /g' \
        -e 's/%21/!/g' \
        -e 's/%22/"/g' \
        -e 's/%23/#/g' \
        -e 's/%24/$/g' \
        -e 's/%25/%/g' \
        -e 's/%26/\&/g' \
        -e "s/%27/'/g" \
        -e 's/%28/(/g' \
        -e 's/%29/)/g' \
        -e 's/%2[aA]/*/g' \
        -e 's/%2[bB]/+/g' \
        -e 's/%2[cC]/,/g' \
        -e 's/%2[dD]/-/g' \
        -e 's/%2[eE]/./g' \
        -e 's#%2[fF]#/#g' \
        -e 's/%3[aA]/:/g' \
        -e 's/%3[bB]/;/g' \
        -e 's/%3[cC]/</g' \
        -e 's/%3[dD]/=/g' \
        -e 's/%3[eE]/>/g' \
        -e 's/%3[fF]/?/g' \
        -e 's/%40/@/g' \
        -e 's/%5[bB]/[/g' \
        -e 's/%5[cC]/\\/g' \
        -e 's/%5[dD]/]/g' \
        -e 's/%5[eE]/^/g' \
        -e 's/%5[fF]/_/g' \
        -e 's/%60/`/g' \
        -e 's/%7[bB]/{/g' \
        -e 's/%7[cC]/|/g' \
        -e 's/%7[dD]/}/g' \
        -e 's/%7[eE]/-/g'
}

myVariable=`brute_force_percent_decode "||parameter_value||"`

Configure parameter inputs for a sensor

Parameter Inputs that you add to a sensor configuration determine the prompts that a user must complete when issuing a question with the sensor. When you Create a sensor, add each parameter that the Script for a parameterized sensor uses to reference the value that the user enters:

  1. On the sensor configuration page, go to the Parameters section and select Add Parameter > <Type>. For descriptions of the types, see Parameter types.
  2. In the Key field, specify the parameter name that the script uses (see Parameter names) but without the double vertical bars (||) that enclose the parameter in the script. Console includes the bars automatically when you add a parameter to the sensor configuration. The figure Parameter inputs shows an example of the Path parameter.
  3. Enter a Label to identify the parameter in the Interact workbench when users issue a question.
  4. (Optional) Configure Options for the parameter. The options vary by parameter type. For more information, see Parameter options.
  5. (Optional) Configure Validation Expressions for the parameter types List, Text Area, and Text Input. For more information, see Validation expressions.
  6. Verify that the parameter looks and behaves as expected in the Preview section, which shows how users see the parameter when they issue a question. For example, you can enter values to test any limits that you configured in the Options.
Figure 8. Parameter inputs
Parameter inputs

Parameter types

The most common type of user-input widget for a parameter value is a text-entry field (Text Input type), but you can select any of the following types.

Table 1. Parameter types

Parameter type

Description

Checkbox

Users select a checkbox to enable a setting (set the parameter value to 1) or clear the checkbox to disable the setting (set the value to 0).

Date

Users enter a date or select a date through the Calendar widget Calendar. Set the 1time standard to Local Time or UTC. Set the 2Default Value to Now or a Specific date.

Date Time

Users enter a date and time or select a date and time through the Calendar Calendar and Clock Clock widgets. Set the 1time standard to Local Time or UTC. Set the 2Default Value to Now or a Specific date/time.

Date Time Range

Users specify a start date/time and end date/time. For the End Date setting, select Require if users must specify an end date/time or clear the checkbox if the end date/time is optional. Set the 1time standard to Local Time or UTC.

Drop Down List

Users select only one item from a drop-down list. To specify each value that users can select, go to the Values section, click + add value and enter the value.

List

Users enter one or more values and use a pipe "|" to delimit multiple values. Entering a value is optional instead of required if List Is Optional is selected in the parameter Options. To define the allowed values, see Validation expressions.

Numeric

Users enter a number.

Numeric Interval

Users enter a number and select the associated unit from a list. The unit has a numeric value (interval) that Interact multiplies by the user entry to determine the parameter value. For example, the list might include the units Seconds, Minutes, and Hours with the corresponding values 1, 60, and 3600 respectively. In this case, if a user enters 2 and selects Hours, the parameter value is 7200 (2 * 3600). To specify each unit that users can select, go to the Interval Units section, click + add interval, enter a label for the unit, and enter its value.

Separator

This type is not a parameter input but a graphical separator that helps users to distinguish different sections of the user input form when entering parameter values. If a user must specify multiple values, you can use sections to visually organize related parameters in the input form. The Separator text that you specify appears as the section title and has a line below it.

Text Area

Users enter a large amount of text that can include multiple lines. To define the allowed values, see Validation expressions.

Text Input

Users enter a single line of text. To define the allowed values, see Validation expressions.

Time

Users enter a time or select a time through the Clock widget Clock. Set the 1time standard to Local Time or UTC. Set the 2Default Value to Now or a Specific time.

1 Local Time is local to the system that you use to access Console. UTC is Coordinated Universal Time.

2 Now is the current date/time when users specify a value for the parameter.

Parameter options

Use parameter Options to limit the range of values that users can enter, control how the Interact workbench presents a parameter, or provide help information that users see when entering values. The figure Parameter inputs shows an example of information that you can specify for a Text Input parameter to help users understand what to enter. The options that are available vary by parameter type. Only the Separator type has no options.

Note: For the options of date/time parameters, set the time standard (Local or UTC) in the required settings of the parameters. For more information, see Parameter types.
Table 2. Parameter options

Parameter option

Description

Parameter types

Date Limits

Restrict user entries to within a minimum and/or maximum date. For each limit, select a Specific date through the Calendar widget Calendar or select Future Only or Past Only.

Date

Date Time

Enable drill-down autofill

This option applies only to parameterized sensors, not parameterized packages. Select the option to auto-populate a parameterized sensor in a drill-down question with the values of matching parameters in the results that the user selects in the Question Results grid. For more information, see Drill down into results.

All types

Default Start/End Date

Specify a default start and/or end date. For each date, select a Specific date through the Calendar widget Calendar or select Future Only or Past Only.

Date Time Range

Provide Default Value

Enter a default value to appear in the parameter input field. For list parameters, specify one value for each line. Users can overwrite the default value with a custom value.

List

Numeric

Numeric Interval

Text Area

Text Input

Provide Height in Lines

Specify the vertical height of a text area parameter. This option controls only the display size of the text-entry field, not the number of lines that users can enter. For example, if you enter 3, the text-entry field appears 3 lines high but users can enter more than 3 lines of text.

Text Area

Provide Help Text

This option adds an Information icon Info beside the parameter name in the user input form. When a user hovers over the icon, a tooltip shows the text that you specify for this option.

Provide Help Text

All types

Provide Max Chars

Specify the maximum number of characters that users can enter for the parameter value.

Text Area

Text Input

Provide Maximum Value

Specify the highest number that users can enter for the parameter.

Numeric

Numeric Interval

Provide Minimum Value

Specify the lowest number that users can enter for the parameter.

Numeric

Numeric Interval

Provide Prompt Text

Enter read-only text to appear in the parameter input field. The text is not a value for the parameter but typically explains what value to enter. If you also configure the Provide Default Value option, users initially see the default value and then see the prompt text only if they delete the default value.

Text Area

Text Input

Provide Restrict Expression

Enter a regular expression that defines the allowed values. For example, the expression A‑Za‑z allows alphabetic characters but not numbers or special characters.

Tip: You can also use Validation Expressions to define the allowed values. For more information, see Validation expressions.

List

Provide Snap Interval

Use this option if the parameter value that a user enters must be divisible by the snap interval value.

Numeric

Numeric Interval

Provide Step Size

Specify the amount by which users can increase or decrease the value of a numeric parameter. Enter a step size that is a multiple of the Provide Snap Interval value unless the snap interval is set to 0.

Numeric

Numeric Interval

List Is Optional

Select this option if entering a value for a List parameter is optional instead of required.

List

Selected

Select this option for a Checkbox parameter that must be selected by default. Users can manually clear the checkbox.

Checkbox

Time Limits

Restrict user entries to within a minimum and/or maximum time. For each limit, select a Specific time through the Clock widget Clock or select Future Only or Past Only.

Date Time

Time

Validation expressions

For the parameter types List, Text Area, and Text Input, you can add Validation Expressions to define the allowed values. The expressions are based on Perl Compatible Regular Expressions (PCRE). Boolean AND logic applies if you add fields for multiple expressions. You can apply Boolean OR logic to multiple expressions by entering them as a single field entry with pipes "|" as separators. Each expression field has an adjacent text box where you can enter a description to help users understand the expression. For example, if the expression is \S{5}, you might enter the help text Value must be at least 5 characters.

Note: Include validation for input parameters when you write the sensor or package script, not just in Validation Expressions. For more information, see Script for a parameterized sensor and Package script and command-line parameters.
Note: The validation does not apply to custom sensors that you import or that you create through the Tanium API because it is Console that validates expressions, not Tanium Cloud.