To access a variable from the Groovy script of an event rule or trigger
Introduction:
Variables allow administrators to make a single change that can be picked up by multiple rules. For example, variables are useful in the following cases:
- if you have actions that send an email: rather than typing the email address into each action, you can create a variable that contains the email address. If the email address changes, you can simply update the variable, and all the actions that use the variable will also be updated.
- to control when particular actions are enabled: using the example of an action that sends an email, you could add a test against a variable, so that an email would only be generated when the variable contains the value true.
To create a new variable:
- Click the Main Menu and then Administration.
- On the Administration page, click Event Administration.
- On the Event Administration page, click the Variables tab, and then click Add.
- This will open the New Variable window. Enter a Name and Description for the new variable in those fields.
- Enter the value of the variable in the Value field. This value must be entered in a format suitable for Groovy syntax:
- numbers are entered verbatim, e.g. 1.
- strings are enclosed within quotes, e.g. "an.employee@entuity.com".
- At this point you can click OK to save the variable, otherwise click Cancel.
The Choose button is optional, and enables you to specify between specifying a Function Call or Variable Reference, depending on what you want the variable to do. For example, it is used when specifying an incident that triggers an email when raised.- Click Choose to open the Choose Variable or Function window.
- In the Value Kind dropdown field, select either Function Call or Variable Reference, depending on what you want the variable to do.
- Function Call allows you to select from the following functions in the Function dropdown field:
- lookupDevice - looks up inventory for a device by its name or IP address.
- lookup Port - looks up inventory for a port by its name or IP address and ifIndex.
- Once you have selected your function, select a parameter from the Parameters field and click Set.
- Variable Reference allows you to select from a previously saved variable that you have created.
- Function Call allows you to select from the following functions in the Function dropdown field:
- Click OK to save, otherwise click Cancel.
To access a variable from the Groovy script of an event rule or trigger:
You can access the value of a variable from within the Groovy Script (in either a condition or action) of an event rule or trigger. The required Groovy syntax is as follows:
def varValue = var("myVariableName")
Comments
0 comments
Please sign in to leave a comment.