top of page

Sending Emails on VCF Automation Deployments

  • Writer: Brock Peterson
    Brock Peterson
  • 7 days ago
  • 2 min read

I wanted to send email notifications to the VCF Automation team on VM Deployments, it wasn't quite as easy as expected, here's how I did it!


First, I added all the Properties I wanted to include in the email to my VCFA Blueprints. Here's a code snippet, but if you'd like the full Blueprint you can get it here.


Cloud_vSphere_Machine_1:

type: Cloud.vSphere.Machine

properties:

image: ${input.os}

cpuCount: ${input.vcpuCount}

totalMemoryMB: ${input.totalMemoryMB}

name: ${input.vmname}

vm_snapshot: ${input.vm_snapshot}

notes: ${input.notes}

owner: ${input.owner}

description: ${input.description}

category: ${input.category}

vmname: ${input.vmname}

vcpu: ${input.vcpuCount}

memoryMB: ${input.totalMemoryMB}


Once deployed, you can see the Custom Properties in the VCFA Deployment.



These are the Properties I'll use in the post-deployment Workflow to construct the email. The Orchestrator Workflow looks like this, if you'd like the Workflow (Package) you can get it here.



It takes the VCFA Deployment Custom Attributes as Inputs and constructs the email. Specifically, it extracts what we need from Custom Properties, adds the SMTP server, SMTP port (and more) and sends it to the Send Notification (TLSv1.2) Workflow Element. The JavaScript looks like this:


// Read values from customProperties

var customProperties = inputProperties.get("customProperties");

var vm_name = customProperties.get("vmname");

var vm_os = customProperties.get("osType");

var vm_vcpu = customProperties.get("vcpu");

var vm_memory = customProperties.get("memoryMB");

var vm_owner = customProperties.get("owner");

var vm_category = customProperties.get("category");

var vm_description = customProperties.get("description");

var vm_notes = customProperties.get("notes");

var vm_snapshot = customProperties.get("vm_snapshot");


// Outputs

smtpPort = 587;

fromName = "VCF Automation (Brock Peterson)";

subject = "VCF Automation Notification: " + vm_name;

content =

"A VM has been provisioned by VCF Automation (vra-bpeterson.vcfops.lab), here are the details:<br><br>" +

"<b>VM Name:</b> " + vm_name + "<br>" +

"<b>VM OS:</b> " + vm_os + "<br>" +

"<b>VM vCPU:</b> " + vm_vcpu + "<br>" +

"<b>VM Memory (MB):</b> "  + vm_memory + "<br>" +

"<b>VM Owner:</b> " + vm_owner + "<br>" +

"<b>VM Category:</b> " + vm_category + "<br>" +

"<b>VM Description:</b> " + vm_description + "<br>" +

"<b>VM Notes:</b> " + vm_notes + "<br>" +

"<b>VM Snapshot Taken:</b> " + vm_snapshot + "<br><br>" +

"Any issues contact the VM Owner!";


The Send Notification (TLSv1.2) Workflow Element looks like this.



It takes Inputs from our previous Scriptable Task.


To run this Orchestrator Workflow upon VM deployment I created a Subscription based on the Compute Post Provision Event.



Now when a user requests a VM, like this.



Once complete, I get an email like this.



Yet another use case for Orchestrator Workflows and Subscriptions. Hope this was helpful, enjoy!

Comments


    bottom of page