Example: Parameterized packages

Overview of parameterized packages

A parameterized package requires you to enter input (parameter values) when configuring an action that uses the package. For example, when you configure an action that uses the package Open Share Inventory, the Action Deployment page prompts you to enter the Minimum minutes between runs and other parameters. The package configuration specifies a command (such as cmd.exe) and script (such as ShareInventory.ps1) that require the parameters. When you configure the action, the Tanium Server saves the package definition in an object called a temporary package, which includes the parameter values that you entered. The Server then deploys the action with the temporary package to Tanium Clients, which run the package at the action start time.

Figure 1. Parameterized package
Parameterized package

To create a parameterized package, configure the Command, script Files, and Parameter Inputs as described in the following sections when you perform the steps in Create a package:

Important: For more information about the impact on scheduled actions when a parameterized package configuration is updated, see Scheduled action with parameterized package.

Package script and command-line parameters

When you Create a package that uses parameters, the Command specifies an executable such as a script engine. The script for a parameterized package has the requirements described in Parameter positions and UTF-8 encoding and decoding.

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

Parameter positions

In a package configuration, the command-line variables in the Command field must match the parameter numbers in the Parameter Inputs section. In the package Open Share Inventory for example, the Command includes variables that are numbered $1 to $7:

cmd.exe /d /c powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NonInteractive -NoProfile -File "%CD%\ShareInventory.ps1" -MinMinsBetweenRuns $1 -InventoryDefaultShares $2 -InventoryFolderPerms $3 -ExcludedShares $4 -ExcludedPermissionedObjects $5 -Remove $7 -Validation $6

Important: In the Command field, enclose parameters in quotation marks "<parameter name>" if their names have spaces.

The corresponding Parameter Inputs lists the parameters with numbers that match the Command variables:

Figure 2. Parameter positions in a package
Parameter positions in a package
Note: Parameter numbers do not apply to the input type Separator, such as - Exclusions - in the preceding example.

The package configuration might include parameters that the script does not include. For example, the package Open Share Inventory specifies the Validation $6 parameter because it requires user input. However, the associated PowerShell script ShareInventory.ps1 does not process that parameter and therefore does not include it:

CODE
param (
	[int]$MinMinsBetweenRuns = 720,
	[int]$InventoryFolderPerms = 1,
	[int]$InventoryDefaultShares = 1,
	[string]$ExcludedShares = ' ',
	[string]$ExcludedPermissionedObjects = ' ',
	[int]$Remove = 0
)

The parameter numbering in the script for a VBScript package might not match the parameter numbering in the Command and Parameter Inputs of the package configuration. For example, the script parameters are numbered 0 to 4 in the set-value.vbs script for the package Registry - Set Value because VBScript treats an un-named argument list as a zero-based array:

CODE
targetArch = Trim(LCase(WScript.Arguments.Item(0)))
targetKey = UTF8Decode(WScript.Arguments.Item(1))
targetValueName = UTF8Decode(WScript.Arguments.Item(2))
targetValue = UTF8Decode(WScript.Arguments.Item(3))
targetValueType = UTF8Decode(WScript.Arguments.Item(4))

By contrast, the corresponding Command variables are numbered $1 to $5 in the package configuration:

cmd.exe /d /c ""%WinDir%\System32\cscript.exe" //E:VBScript //T:60 set-value.vbs "$1" "$2" "$3" "$4" "$5""

UTF-8 encoding and decoding

When you deploy an action with a parameterized package, the Tanium Server encodes the parameter values that you enter before passing the values to the package script. The Server includes the encoded values in the temporary package that it deploys in an action to Tanium Clients. When Clients start the action, they run the package script and the script applies UTF-8 decoding to the encoded values.

PowerShell package scripts use the .NET method [System.Uri]::UnescapeDataString() to decode UTF-8 encoded parameters. For example, the script ShareInventory.ps1 for the package Open Share Inventory uses:

CODE
$ExcludedShares = [System.Uri]::UnescapeDataString($ExcludedShares)

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

Figure 3. 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 4. 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 5. 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 package

Parameter Inputs that you add to a package configuration determine the prompts that a user must complete when deploying an action that uses the package. On the package configuration page, add one parameter input at a time in an order that matches the corresponding command-line variables. The first parameter that you add is matched to command line variable $1, the second parameter is matched to variable $2, and so on as described under Parameter positions.

Tip: You can select and drag items in the Parameter Inputs list on the package configuration page to ensure that the items line up with the numbered parameters in the command.
  1. When you Create a package, go to the Parameters section of the package configuration page and select Add Parameter > <Type>. For descriptions of the types, see Parameter types.
  2. Enter a Label to identify the parameter in the Interact workbench when users deploy an action.
  3. (Optional) Configure Options for the parameter. The options vary by parameter type. For more information, see Parameter options.
  4. (Optional) Configure Validation Expressions for the parameter types List, Text Area, and Text Input. For more information, see Validation expressions.
  5. Verify that the parameter looks and behaves as expected in the Preview section, which shows how users see the parameter when they deploy an action. For example, you can enter values to test any limits that you configured in the Options.
Figure 6. Parameter inputs
Parameter input settings

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 the Tanium Server.