Walk-Through: Creating a Workflow

This example workflow shows 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

This example uses a command workflow, but the steps are similar for all workflow types. This command workflow backs up a VM, sets the VM backup time, and then notifies the VM owner that the VM has been backed up, providing the backup time in the email.

Create a custom attribute

Before creating the workflow, create a custom attribute to store the VM's last backup time. You will set a value for the custom attribute in a workflow step.

  1. Click Configuration > Custom Attributes, and click Add.
  2. In the Configure 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 Text type.
  4. Specify that the custom attribute should apply to Services, and click Next.

    Define Attribute

  5. On the Configure Attribute page, leave the default selection, and click Finish.

Create the 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 pane, 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.

    example_exec_script_step

  8. To add a Set Custom Attribute step, click Add > Lifecycle Management > Set Custom Attribute.
  9. In the details pane, 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.

    Set Backup Time

  11. Add a Send Email step, click Add > Send Email.
  12. In the details pane, 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']}".

    example_email_step

    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 this workflow, then click Next.
  18. On the Options page, enable 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.