Are you sick of the Event Broker yet? ME NEITHER!!! In this post we illustrate how to utilize the Event Broker to send custom html emails. Using vRealize Automation 7 to create Custom Email Notifications with the Event Broker your usability and customer satisfaction can improve!

It’s well known that you can set up out of the box notifications from vRA and thankfully in version 7 it’s on by default but there are still many customers asking me for improved customizable emails vs. what is posted in this kb.

So without further ado here’s the example video!

You can download the package used here from this link

For the simple comparison sake let’s start with the out of the box templates. It’s a good example of nothing custom. Very informative and great content.

“I want something more like this that I can play with and customize based on custom properties or other specific content”

We will start by editing the workflow Send custom notification – State Transition

Change the parameters to meet your environment needs

A quick overview of the schema as you can see we collect data, make a decision and either send or not based on that decision.

Let’s edit the Get Properties

In this scriptable task we are using the standard examples to collect the properties and we are also building the logic for whether we send an email and what that email content is.

Here’s the full script that I used in the screens above I’ve highlighted a few of the excerpts you may want to adjust. Examples of what you may want to change are the content of the email (Logo is a good example). You could also uncomment any of the lines between requested and activated if you wanted to give updates at each state.

var executionContext = System.getContext();

System.log(“BlueprintName: ” + payload.get(“blueprintName”)) ;

System.log(“ComponentId: ” + payload.get(“componentId”)) ;

System.log(“ComponentTypeId: ” + payload.get(“componentTypeId”)) ;

System.log(“EndpointId: ” + payload.get(“endpointId”)) ;

System.log(“RequestId: ” + payload.get(“requestId”)) ;

System.log(“VirtualMachineEvent: ” + payload.get(“virtualMachineEvent”)) ;

System.log(“WorkflowNextState: ” + payload.get(“workflowNextState”)) ;

var lifecycleState = payload.get(“lifecycleState”) ;

System.log(“State: ” + lifecycleState.get(“state”)) ;

System.log(“Phase: ” + lifecycleState.get(“phase”)) ;

System.log(“Event: ” + lifecycleState.get(“event”)) ;

var machine = payload.get(“machine”) ;

System.log(“ID: ” + machine.get(“id”)) ;

System.log(“Name: ” + machine.get(“name”)) ;

System.log(“ExternalReference: ” + machine.get(“externalReference”)) ;

System.log(“Owner: ” + machine.get(“owner”)) ;

System.log(“Type: ” + machine.get(“type”)) ;

System.log(“Properties: ” + machine.get(“properties”)) ;

var vRAVmProperties = machine.get(“properties”) ;

if (vRAVmProperties != null) {

var log = “”;

log += “vRA VM properties :n”;

var array = new Array();

for each (var key in vRAVmProperties.keys) {

array.push(key + ” : ” + vRAVmProperties.get(key));

}

array.sort();

for each (var line in array) {

log += “t” + line + “n”;

}

System.log(log);

}

var IP = vRAVmProperties.get(“VirtualMachine.Network0.Address”);

var OS = vRAVmProperties.get(“custom.os”)

System.log(“IP = ” + IP);

System.log(“OS = ” + OS);

if (OS == ‘linux’){ var ipUrl = “ssh://” + IP;}

if (OS == ‘windows’){ var ipUrl = “rdp://” + IP;}

System.log(“ipUrl is ” + ipUrl);

var ls=lifecycleState.get(“state”)

if (ls == ‘VMPSMasterWorkflow32.Requested’){ var subState = “Your self service request has been submitted”;}

/*if (ls == ‘VMPSMasterWorkflow32.WaitingToBuild’){ var subState = “Your self service request is waiting to be built”;}

if (ls == ‘VMPSMasterWorkflow32.BuildingMachine’){ var subState = “Your self service request has been successfully built waiting on activation”;}

if (ls == ‘VMPSMasterWorkflow32.MachineProvisioned’){ var subState = “Your self service request is provisioned waiting on activation”;}

*/

if (ls == ‘VMPSMasterWorkflow32.MachineActivated’){ var subState = “Your self service request is activated and ready for use”;}

/*if (ls == ‘VMPSMasterWorkflow32.DeactivateMachine’){ var subState = “Your self service request has been deactivated and being torn down”;}

if (ls == ‘VMPSMasterWorkflow32.UnprovisionMachine’){ var subState = “Your self service request is unprovisioned and awaiting disposal”;}

*/

if (ls == ‘VMPSMasterWorkflow32.Disposing’){ var subState = “Your self service request has been completely disposed”;}

System.log(“Your subState is ” + subState);

if (subState != null){

System.log(“Setting the to email”);

var emailRequired=”true”;

var toAddress = machine.get(“owner”);

var subject = subState ;

System.log(“Building content line by line”);

content = ‘<img src=”https://extendingclouds.com/wp-content/uploads/2016/04/logo_BBR_003-3.jpg” alt=”biteback logo”>’ +

‘<h2>Thank you for your request!</h2>’+

‘<p>This is an email to let you know your request is in process and you will get updates throughout</p>’ +

‘<p></p>’ +

‘<h3>Your request for ‘ + payload.get(“blueprintName”) + ‘ ‘ + subState + ‘ </h3>’ +

‘<p></p>’ +

‘<ul>’ +

‘<li>Your machine is named: ‘ + machine.get(“name”) + ‘ </li>’ +

‘<li>Is being provisioned with the following CPU: ‘ + vRAVmProperties.get(“VirtualMachine.CPU.Count”) +

‘, RAM: ‘+ vRAVmProperties.get(“VirtualMachine.Memory.Size”) +

‘, and DISK: ‘ + vRAVmProperties.get(“VirtualMachine.Disk0.Size”) + ‘ </li>’ +

‘<li>Will be available at the following IP Address: <a href=”‘ + ipUrl + ‘”> ‘ + ipUrl + ‘</li>’ +

‘<li>Will expire in ‘ + vRAVmProperties.get(“__Cafe.Request.VM.LeaseDays”) + ‘ days</li></ul>’;

}else{

System.log(“Canceling email send”);

var emailRequired=”false”;

}

Next log into the vRA console as an administrative user and go to Administration -> Property Dictionary -> Property Groups. If you followed other post such as Enabling the Event Broker you should already have a property group that passes the properties at the different state changes.

If not create one with the following entries.

Now go to the Design and select the blueprint you will be requesting

Click on the blueprint go to properties tab and then the custom properties. If you don’t already have it create a new property custom.os with a value of the operating system linux or windows *NOTE CASE SENSITIVE. This is part of the code we highlighted earlier which decides if we pass SSH or RDP

Finally we’ll create the subscription by going to Administration -> Events -> Subscriptions -> +New

Select machine provisioning

Run based on conditions. We do this because we want it to only run once per state and to only happen when that state phase is complete (POST)

Select Data – Lifecycle State – State phase

Equals -> POST

Select the workflow “Send custom notification – State Transition”

Just click next

Then publish the new subscription

Now cross your fingers, hold your breath, what ever it is you do to hope it works. Go to the catalog and request your blueprint.

Go back to your vRO instance and review the workflow as it runs (be patient).

Request will fire the workflow and send your custom notification

Building state will fire the work flow but will not send the notification. This is all defined in our scriptable task above.

Now you have successfully gotten your own custom emails using the event broker method. Stay tuned for part 2 which will address a know issue when using software components.

Like this: Like Loading...