Sample Groovy Script Action: Service Attribute Checker
Your CentraSite installation contains a sample Groovy action rule (ServiceAttributeChecker.groovy) that you can use to create a custom action that checks for a particular value of a service attribute.
To create and test the custom action, you will use the CentraSite user interface to:
1. Create a custom action category
2. Create a custom action template, to which you upload the sample Groovy script rule
3. Create a Design/Change-Time policy and add the custom action template to it
4. Test the custom action "on demand" (manually) on the policy's detail page
To create and test the custom action Service Attribute Checker
1. In CentraSite Control, go to Policies > Action Templates.
2. Click the Add Action Category button.
3. In the Add Action Category dialog box, do the following:
a. Specify a name for the new custom category, for example My Custom Actions. An action category name can contain any character (including spaces).
b. Choose Design/Change-Time as the action category type.
c. Click OK.
The action category that you created appears as a custom category next to an icon in the Policy Information panel.
4. Click Add Action Template.
5. On the Add Action Template page, specify the following fields:
In this field... | Do the following... |
Category | Select the custom action category you just created. |
Name | Enter the name Service Attribute Checker for the new action template. |
Description | Optional. Type a description for the new action template. For example: Validates asset attribute values. |
Implementation | Select Groovy. |
Uploaded File | Click the Browse button and upload the following rule file: <CentraSite_Install_Dir>\demos\Custom actions\Groovy\ServiceAttributeChecker.groovy |
In the Scope panel, specify the following fields and click Save:
In this field... | Do the following... |
Object Types | Select Service as the type of object to which this action template applies. |
Event Types | Select OnTrigger as the type of event to which this action template applies. This will enable you to test the action "on demand" (manually) in the Actions profile of the Design/Change Time Policy Detail page. |
6. In the Edit Action Template Detail page, select the Parameter Templates profile in order to add the action's parameter templates and click the Add Parameter Template button.
7. Set the first parameter template for the action as follows:
In this field... | Do the following... |
Name | Enter Attribute Name. This parameter will hold the attribute that you want to check (for example, any CentraSite attribute, which you will assign after you add the action to a policy). |
Type | Choose the data type Attribute for this parameter template. |
Default Value | Leave blank. |
Array | Leave blank. |
Required | Select this check box. |
8. Click the Add Parameter Template button again to set the second parameter template as follows:
In this field... | Do the following... |
Name | Enter Possible Attribute Value. This parameter will hold the value of the attribute that you want to check. |
Type | Select the data type String for this parameter template. |
Default Value | Enter an attribute value that you want to check. |
Array | Leave blank. |
Required | Select this check box. |
9. Click Save and then Close.
The parameter template that you added appears in the Parameter Templates profile.
10. Create a policy and add the sample action to the policy as follows:
a. In CentraSite Control, go to Policies > Design/Change Time.
b. Click Add Policy.
c. In the Policy Information panel, enter a name for the new policy, for example, Service Attribute Checker Policy. A policy name can contain any character (including spaces).
d. In the Scope panel, specify the object and event types to which the policy applies as follows:
In the
Object Types field, select
Service as the type of object to which this policy applies.
In the
Event Types field, select
OnTrigger as the type of event to which this policy applies.
In the
Organization field, select your organization name as the organization to which this policy belongs (and to whose objects the policy will be applied).
e. Click Next.
f. From the Available Actions list, choose the custom action Service Attribute Checker action that you created.
g. Click Finish to save the new (as yet incomplete) policy. The Design/Change-Time Policy Details page is displayed.
h. To configure the two parameters for the action, choose the action name on the Actions profile. For the Attribute Name parameter, choose an attribute. For the Possible Attribute Value parameter, select the default value that you defined for the Possible Attribute Value parameter in the action template.
i. Click Save and then Close. The policy detail page is displayed.
j. Activate the policy by choosing the Change State button and choosing the Productive state.
k. Select the Actions profile.
l. To test the action, click the Run button. The action checks all services in your organization and displays a pop-up. The pop-up should indicate Success in the Result column for the service that matches the value you specified in Possible Attribute Value. All other services will also be displayed, with Failure in the Result column.
11. After you have completed testing, you can use this custom action in other Design/Change-Time policies. To do this, go to its Scope panel, change the event type from OnTrigger to PreCreate or PreUpdate, and include the action in other Design/Change-Time policies whose event type scope is either PreCreate or PreUpdate.