Using Variables and Functions
From OpsWise Documentation Wiki
Contents |
Overview
OpsWise Automation Center supports the following types of variable, all of which can be used in free text fields within tasks:
- User-Defined Variables -- These variables are created by the user.
- Built-In Variables -- These variables are maintained by the system and allow you to access information about task instances and other related data, such as task name, task status, and trigger name.
- Functions -- These calculate some value, such as current date and time, or perform some function, such as ReplaceAll.
Each of these is described in more detail below.
User-Defined Variables
You can define Opswise variables in four different locations:
- Trigger variables are entered by clicking the Variables tab in a trigger. Trigger variables are stored in the table ops_local_variable.
- Task variables are entered by clicking the Variables tab in a task. Task variables are stored in the table ops_local_variable.
- Workflow variables are entered by clicking the Variables tab in a workflow. Workflow variables are stored in the table ops_local_variable.
- Global variables are entered by selecting Automation Center > Variables from the Navigation Pane. Global variables are stored in the table ops_variable.
Once the task has been launched and the variables are resolved, they are referred to as task instance variables. The task instance variables are stored in hashed format in the table ops_map_table.
You can manually launch tasks and temporarily set user-defined variables. Click here for instructions.
Important Note -- Do not define OpsWise Automation Center variables with the prefix “ops_”. That prefix is reserved for built-in variables.
Resolving User-Defined Variables
When OpsWise Automation Center creates a task instance from a task definition, it also resolves all variables specified in its free text fields. Because you can define variables at four different levels (trigger, task, workflow, and global), OpsWise Automation Center follows a prescribed formula to determine which variable takes precedence if duplicate variables have been defined. The general order of precedence is: 1) task trigger, 2) task, 3) workflow trigger, 4) workflow, 5) global.
The following scenarios provide more detailed information about how OpsWise Automation Center variables are resolved.
For tasks launched by a trigger:
- If the trigger defines the variable in the variables tab, that value is used to resolve the variable.
- If the trigger does not define the variable, the value from the variable tab in the task definition is used.
- If neither the trigger nor the task define the variable, the variable definition in the global variables table is used.
- If the global variables table does not define the variable, the variable remains unresolved.
For tasks launched by a workflow:
- If the task defines the variable in the variables tab, that value is used to resolve the variable.
- If the task does not define the variable, and the workflow was launched by a trigger, the value defined in the trigger is used.
- If the workflow's trigger does not define the variable or the workflow was not launched by a trigger, the value defined in the workflow is used.
- If the workflow does not define the variable, and there is a parent workflow, the value defined in the parent workflow's trigger is used. If the trigger does not define the variable or if there is no trigger, the value defined in the parent workflow is used. If the parent workflow does not define the variable, the system checks up a level for another parent workflow and repeats the process. This continues until the top level workflow is reached.
- If the top-level workflow does not define the variable, the variable definition in the global variables table is used.
- If the global variables table does not define the variable, the variable remains unresolved.
For tasks launched manually:
- If the task defines the variable in the variables tab, that value is used to resolve the variable.
- If the task does not define the variable, the variable definition in the global variables table is used.
- If the global variables table does not define the variable, the variable remains unresolved.
Format for Using Variables
When you enter a variable into a text field, precede the variable with the dollar sign ($) and enclose the variable in curly braces. You can enter a series of variables or nested variables. Examples are:
${variable_name}
${v1}${v2}
${${inner_variable}}
Creating a New Variable
- For global variables, select Variables from the Navigation Pane. For trigger, task, or workflow variables, click on the Variables tab from the record. OpsWise Automation Center displays a list of variables, if any, as shown in the example below.
- From the wizard, select New. OpsWise Automation Center displays the Variable screen:
- Using the field descriptions provided below as a guide, complete the fields as needed.
- Click the Submit button to save the record and return to the menu, or, right-click and select Save to save the record and remain on the current display.
- If appropriate, repeat these steps for any additional variables you want to add.
Variable Field Descriptions
The table below describes the fields and buttons on the Variables screen.
| Field Name | Description |
|---|---|
| Name | Required. Name used within OpsWise Automation Center to identify this variable. Up to 40 alphanumerics; no spaces. It is the user’s responsibility to develop a workable naming scheme for tasks. Important Note -- Do not define OpsWise Automation Center variables with the prefix “ops_”. That prefix is reserved for built-in variables. |
| Value | Optional. The value of the variable, if any. |
| Description | Optional. The description of the variable, if any. |
| Submit button | Submits the new record to the database. |
| Update button | Saves updates to the record. |
| Delete button | Deletes the current record. |
Built-In Variables
Built-in variables are maintained by OpsWise Automation Center. They can be used in free text fields and provide information about tasks instances and triggers. They are resolved when the task is launched into a task instance. Some of them are available when a notification is created for an agent, cluster, or connector changes status. Supported built-in variables and their descriptions are provided in the table below. All built-in variables are prefixed with “ops_”.
| Name | Description |
|---|---|
| The following built-in variables are associated with task instances: | |
| ${ops_agent_hostname} | Resolves to the agent hostname. |
| ${ops_agent_id} | Resolves to the agent connection name. |
| ${ops_agent_ip} | Resolves to the agent IP address. |
| ${ops_agent_name} | Resolves to the agent name. |
| ${ops_cmd} | Resolves to the task command. |
| ${ops_cmd_parms} | Resolves to the task command parameters. |
| ${ops_exit_code} | Resolves to the task instance exit code. |
| ${ops_retry_count} | Resolves to the current retry count. |
| ${ops_retry_interval} | Resolves to the retry interval (seconds). |
| ${ops_retry_maximum} | Resolves to the maximum retry count. |
| ${ops_status} | Resolves to the current task instance status. |
| ${ops_task_id} | Resolves to the sys_id of the task instance. |
| ${ops_task_name} | Resolves to the task instance name. |
| ${ops_task_type} | Resolves to the task instance type. |
| ${ops_start_time} | Resolves to the task starting time. |
| ${ops_end_time} | Resolves to the task ending time. |
| ${ops_duration} | Resolves to the task running time. |
| ${ops_workflow_id} | Resolves to the sys_id of the parent workflow task instance. |
| ${ops_workflow_name} | Resolves to the name of the parent workflow task instance. |
| When a notification is created for the status change of an agent, cluster, or connector: | |
| ${ops_agent_hostname} | Resolves to the agent hostname. |
| ${ops_agent_id} | Resolves to the agent connection name. |
| ${ops_agent_ipaddr} | Resolves to the agent IP address. |
| ${ops_agent_name} | Resolves to the agent name. |
| ${ops_agent_mode} | Resolves to the agent operational mode (ACTIVE|OFFLINE). |
| ${ops_cluster_hostname} | Resolves to the cluster hostname. |
| ${ops_cluster_id} | Resolves to the cluster connection name. |
| ${ops_cluster_ipaddr} | Resolves to the cluster IP address. |
| ${ops_cluster_name} | Resolves to the cluster name. |
| ${ops_cluster_mode} | Resolves to the cluster operational mode (ACTIVE|AVAILABLE|OFFLINE). |
| ${ops_connector_hostname} | Resolves to the connector hostname. |
| ${ops_connector_id} | Resolves to the connector connection name. |
| ${ops_connector_ipaddr} | Resolves to the connector IP address. |
| ${ops_connector_name} | Resolves to the connector name. |
| ${ops_connector_mode} | Resolves to the connector operational mode (ACTIVE|AVAILABLE|OFFLINE). |
| When a task is launched by a trigger, the following built-in trigger variables are passed into the task instance: | |
| ${ops_trigger_name} | Resolves to the name of the trigger that launched the task instance. |
| ${ops_trigger_file_name} | File Monitor trigger only. Resolves to the name of the file that fired the trigger. |
| ${ops_trigger_file_size} | File Monitor trigger only. Resolves to the file size of the file that fired the trigger. |
| ${ops_trigger_file_date} | File Monitor trigger only. Resolves to the file date of the file that fired the trigger. |
| ${ops_trigger_file_scan} | File Monitor trigger only. Resolves to the scan results. |
| ${ops_trigger_file_owner} | File Monitor trigger only. Resolves to the file owner of the file that fired the trigger. |
| ${ops_trigger_file_group} | File Monitor trigger only. Resolves to the file group of the file that fired the trigger. |
| ${ops_trigger_task_id} | Task Monitor trigger only. Resolves to the task instance sys_id that fired the trigger. |
| ${ops_trigger_task_name} | Task Monitor trigger only. Resolves to the task instance name that fired the trigger. |
| ${ops_trigger_task_status} | Task Monitor trigger only. Resolves to the task instance status that fired the trigger. |
| ${ops_trigger_task_type} | Task Monitor trigger only. Resolves to the task instance type that fired the trigger. |
| ${ops_trigger_file_name_nopath} | Resolves to the file name without any path information. |
| ${ops_trigger_file_name_simple} | Resolves to the base file name. |
| ${ops_trigger_file_name_extension} | Resolves to the file extension of a file. |
| ${ops_trigger_file_path} | Resolves to the directory where the new file was created, but not the file itself. |
| The following built-in variables are used to pass data into tasks that were launched by an Application Monitor trigger: | |
| ${ops_trigger_appl_name} | Resolves to the name of the Application being monitored by the trigger. |
| ${ops_trigger_appl_status} | Resolves to the status of the Application being monitored by the trigger. |
| ${ops_trigger_appl_type} | Resolves to the type of Application being monitored by the trigger, as defined by the Application Type field. |
| ${ops_trigger_appl_id} | Resolves to the sys_id of the application. |
| The following built-in variables are used in SQL tasks and Stored Procedure tasks to collect SQLException data, if any: | |
| ${ops_sql_error_msg} | Resolves to any error message generated by the database. |
| ${ops_sql_state} | Resolves to a return code that indicates the outcome of the most recently executed SQL statement. |
Triggering with Variables
Overview
OpsWise provides two methods that allow you to manually launch all the tasks associated with a trigger while supplying variable values used by the task(s). These options are available for all trigger types. You will use one of these methods if you want to manually launch the task(s) but cannot use the Launch Task button because you need to override one or more variables.
Two methods are available for triggering tasks while supplying variable values:
- Using the Trigger With Variables popup window. Use this option if you do not want the values you enter for variables to persist. With this option, the values persist only for the time the task(s) is running.
- Using the Variables tab and Trigger Now button. If you want to preserve information about the variables you are setting (the name and value), use the Variables tab.
The variable values you enter when using either option override all others. The variables in the Launch with Variables window override any specified in the Variables tab, but only for this run of the task(s).
The audit message created when you use either method to Trigger with Variables is the same as Trigger Now.
Procedure
Display the Trigger whose tasks you want to launch, and select one of the methods below.
Using the Trigger with Variables Option
- Click the down-arrow or right-click on the title bar to access the Right-Click menu. A menu displays showing the Trigger With Variables option.
- Select Trigger With Variables. A pop-up window displays that allows you to enter up to six variables that will be used when executing the task(s) named in the trigger. These can be existing or new variables.
- When you are finished, click Submit in the pop-up window to launch the tasks named in the trigger. When you click Submit, the variable information in this window is used where referenced in the tasks. After launching the tasks, the system deletes the contents of the window.
Using the Variables Tab
- Click the Variables tab.
- Use the New button to add the variables you want to modify.
- When you are finished, return to the main Trigger page and click Trigger Now to launch the tasks named in the trigger.
Setting Variables in a Workflow
Overview
Within a workflow, you can specify instructions that set a variable to a specific value for use within the workflow. The value you set using this method exists only in memory for the period this workflow is running or until another Set Variable instruction sets it to another value. You can create the Set Variable instruction at the workflow level or task level. If you set it at the workflow level, you have the option of setting it based on the workflow, the tasks (children) in the workflow, or both. If you set it at the task level, you have the option of setting it based on information in the task, in the parent workflow, or both.
The variable need not exist in the database; you can create a new variable using the Set Variable instruction.
When creating a Set Variable instruction, you can trigger the action based on one or more of the following:
- Status
- Exit codes
- Late start
- Late or early finish
Creating a Set Variable Instruction
- Display the workflow for which you want to create Set Variable instructions.
- Click on the Actions tab. This tab displays a list of all Actions for this task, including Set Variables, Email Notifications, and Abort Actions.
- Click New. The Actions wizard displays.
- Click Set Variable. The Set Variables screen displays.
- Using the field descriptions provided below as a guide, complete the fields as needed.
- Click the Submit button to save the record and return to the Actions list, or, right-click and select Save to save the record and remain on the current display.
- If appropriate, repeat these steps for any additional Set Variable instructions you want to add.
Set Variables Field Descriptions
The table below describes the fields and buttons on the Set Variables screen.
| Field Name | Description |
|---|---|
| Action Inheritance | Workflow tasks only. Specifies what records these instructions apply to. Options:
|
| Status | The status of the task instance that will satisfy the trigger. You can specify as many statuses as needed. Options:
|
| Exit Codes | Specifies one or more exit codes that will trigger the Set Variable. If you specify an exit code, you must also specify at least one status. Use commas to separate multiple exit codes; use a hyphen to specify a range. Example: 1, 5, 22-30. |
| On Late Start | Execute the Set Variable if the task started late, based on the Late Start Time specified in the task. |
| On Late Finish | Execute the Set Variable if the task finishes late, based on the Late Finish time specified in the task. |
| On Early Finish | Execute the Set Variable if the task finishes early, based on the Early Finish Time specified in the task. |
| Variable Scope | Applies to variables associated with a task in a workflow. Options:
|
| Name | Required. Name of variable being set. Up to 40 alphanumerics. |
| Value | Optional. The value being written to the variable. |
| Description | Optional. The description of the variable, if any. |
| Submit button | Submits the new record to the database. |
| Update button | Saves updates to the record. |
| Delete button | Deletes the current record. |
Listing and Setting Variables From the Command Line
You can use the ops-variable-set command to set variables. See Command_Line_Interface_Reference#Table_of_Commands for instructions.
Functions
OpsWise Automation Center supports a number of functions that can be specified in free text fields. They are resolved when the task is launched into a task instance. They are entered using the following formats:
${_function}
${_function(arg1, … , argn)}
The following table lists and describes each supported function.
| Name | Description |
|---|---|
| ${_currentTimeMillis} | Resolves to the current time in milliseconds. |
| ${_date([format, day_offset, hour_offset, minute_offset])} | Resolves to the current date and time. All parameters are optional.
Parameters:
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Examples:
|
| ${_dateadv([format, year_offset, month_offset, day_offset, hour_offset, minute_offset])} | Resolves to the current date and time. All parameters are optional.
Parameters:
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Examples:
|
| ${_guid} | Resolves to a 32 byte GUID (Globally Unique ID). |
| ${_hostname} | Resolves to the hostname of the machine running the Core, if available. |
| ${_indexOf(value, str)} | Returns the index within the string value of the first occurrence of the specified substring, str.
Parameters:
If the str argument occurs as a substring within the value, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned. |
| ${_ipaddress} | Resolves to the IP address of the machine running the Core. |
| ${_lastIndexOf(value, str)} | Returns the index within the string value of the rightmost occurrence of the specified substring, str.
Parameters:
If the str argument occurs one or more times as a substring within the value, then the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned. |
| ${_random([max, min])} | Generates a random number between max (inclusive) and min (inclusive).
Parameters:
|
| ${_replaceAll(value, regex, replacement)} | Replaces each substring of value that matches the specified regular expression, regex, with the specified replacement, replacement.
Parameters:
|
| ${_resolve(variable_name, default_value)} | Resolves the variable specified by name variable_name and substitutes the default value default_value if the variable cannot be resolved.
Parameters:
|
| ${_resultsAllFromTask(name[, separator])} | Returns all SQL results from a SQL or Stored Procedure task. Columns are separated by the specified separator and rows are separated by a new line.
Parameters:
|
| ${_resultsColumn(name, colname[, rownum, default_value])} | Returns the string value of a row/column from a previously executed SQL task.
Parameters:
|
| ${_resultsColumnByNo(name, colnum[, rownum, default_value])} | Returns the string value of a row/column from a previously executed SQL task.
Parameters:
|
| ${_resultsColumnsCSV(name[, rownum])} | Returns the string values of columns in a specific row in CSV(comma separated values) format.
Parameters:
|
| ${_scope} | This displays all the defined and built-in variables associated with the task instance.
Example:
|
| ${_siblingid(sibling_name)} | Resolves to the sys_id of the first task instance found within the same workflow specified by the sibling name.
Parameters:
Example:
|
| ${_substring(value, beginIndex[, endIndex])} | Returns a new string that is a substring of value. The substring begins at the specified beginIndex and extends to the character at index endIndex -1.
Parameters:
Examples:
|
| ${_toLowerCase(value)} | Converts all of the characters in the value to lower case using the rules of the default locale.
Parameters:
|
| ${_toUpperCase(value)} | Converts all of the characters in the value to upper case using the rules of the default locale.
Parameters:
|
| ${_trim(value)} | Returns a copy of value, with leading and trailing whitespace omitted.
Parameters:
|









