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.

  1. Click Configuration > Custom Attributes, and click Add.
  2. 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.

  3. Select the Inventory attribute type.
  4. Select the Text input type.
  5. Specify that the custom attribute applies to Services, and click Next.
  6. On the Configure Attribute page, leave the default selection, and click Finish.

Create a command workflow

  1. Go to Configuration > Command Workflows.
  2. Click Add to create a new workflow.
  3. 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.
  4. On the Steps page, to add the script to back up the VM, click Add > Execute Script.
  5. In the details section, give the step a name, such as "Back up VM".
  6. In Script Output, specify that the script output should be captured as comment.
  7. 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.
  8. To add a Set Custom Attribute step, click Add > Lifecycle Management > Set Custom Attribute.
  9. In the details section, give the step a name, such as "Set Backup Time".
  10. 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.

  11. Add a Send Email step, click Add > Send Email.
  12. In the details section, give the step a name, such as "Notify Owner".
  13. In the Address List field, type:

    #{target.primaryOwner.email}

  14. In the Email Subject field, enter appropriate text.
  15. 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.

  16. Click Next.
  17. On the Permissions page, decide who will have access to this workflow, then click Next.
  18. On the Options page, select other settings as required, then click Next.
  19. On the Summary page, enter details about the workflow in the Description of Changes field, review the workflow details, then click Finish.