Create Command Workflows with Custom Attributes
This topic provides an example of how to configure a command workflow to back up a VM, set the VM backup time, and send an email to notify the VM owner of the VM back up and the time it occurred.
Through creating the custom attribute and the command workflow, you'll see how to:
- Run a script through a workflow.
- Set VM metadata using the output from a script step.
- Set up email notification through a workflow.
- Use variables to populate email addresses for notification.
The following steps are similar for all workflow types.
Create a custom attribute
Before creating the workflow, create a custom attribute to store the VM's last backup time. You'll set a value for the custom attribute in a workflow step.
- Click Configuration > Custom Attributes, and click Add.
- In the Configure Custom Attribute wizard, enter a name for the attribute, such as "Last Backup Time".
These custom attributes can be displayed on the Details panel of the VM's Summary tab, so you should create user-friendly names.
- Select the Inventory attribute type.
- Select the Text input type.
- Specify that the custom attribute applies to Services, and click Next.
- On the Configure Attribute page, leave the default selection, and click Finish.
Create a command workflow
- Go to Configuration > Command Workflows.
- Click Add to create a new workflow.
- On the Name & Type page, do the following:
- Type a name for the workflow.
- From Target Type, leave the default value of VM.
- Click Next.
- On the Steps page, to add the script to back up the VM, click Add > Execute Script.
- In the details section, give the step a name, such as "Back up VM".
- In Script Output, specify that the script output should be captured as comment.
- In the Command Line box, enter a command line to back up a VM. Include a command to output the backup timestamp, so that the timestamp is captured as a workflow output and can then be used in the next step.
- To add a Set Custom Attribute step, click Add > Lifecycle Management > Set Custom Attribute.
- In the details section, give the step a name, such as "Set Backup Time".
- For the custom attribute you created earlier (
Last Backup Time
), type the following value:#{steps[1].output}
This syntax uses the output of Step 1 in the workflow to input a value for the custom attribute.
- Add a Send Email step, click Add > Send Email.
- In the details section, give the step a name, such as "Notify Owner".
- In the Address List field, type:
#{target.primaryOwner.email}
- In the Email Subject field, enter appropriate text.
- In the Email Body field, type appropriate text, such as:
"The service #{target.deployedName} was backed up on #{target.customAttribute['Last Backup Time']}".
The
<a>
tag is automatically added to links in emails (only the HTTP protocol is supported). For example, if the value of a custom attribute is a link, the value will be formatted as a link in the email.If you don't use HTML markup in the email body, the body is assumed to be plain text;
<br>
and<p>
tags are automatically added for new lines. If you add HTML markup to the email body, however, no additional tags are added. - Click Next.
- On the Permissions page, decide who will have access to this workflow, then click Next.
- On the Options page, select other settings as required, then click Next.
- On the Summary page, enter details about the workflow in the Description of Changes field, review the workflow details, then click Finish.