...building hybrid clouds that can support any device from anywhere
Hey Readers! This post will introduce you to a couple of useful SMA Runbooks to add to your “SMA Utility Belt”. First things first – go here to read about SMA if you are unfamiliar with the solution: http://aka.ms/IntroToSMA.
This post discusses how to leverage three Runbooks to improve the Tenant experience as they request resources in the WAP portal. The process I’ll be covering breaks down in the steps outlined below.
Note Red box denotes what I’ll be covering in this blog post. Obviously overkill to have a VM Host refreshed during a plan subscription. Get fancy and use this example to build from .
Note XML and PS1 files are both provided in the download. Use SMART for Runbook Import and Export to leverage the provided XML files in the above download for an enhanced experience in importing the example solution into your SMA environment.
We start with the Invoke-SubscriptionCreateRunbook, this would essentially be the Runbook that you will tag with “SPF” to be executed on a create event for a plan. Shown as the Dispatcher Runbook in the graphic above, this dispatcher Runbook makes the decision on what to do depending upon what the tenant selected to do. Since any Runbook that is associated with the Create event will fire when that event is triggered, a dispatcher Runbook is leveraged above as the single authority on actions. You build your knowledge here on how to react to requests.
There are essentially four main sections that this Runbook is executing
The Invoke-SubscriptionCreateRunbook leverages the following variables shown below.
Note Regarding Variables The above variables should be reviewed and potentially modified in the XML or PS1 file before importing to ensure they do not conflict with existing assets already within your SMA environment. I’m not going to go into great detail on the above variables since they should all be fairly self explanatory. If you import these Runbooks with the SMART for Runbook Import and Export, it will create the variables (as defined by me) that will need to be updated with your environment settings. Alternatively, you can update this Runbook (once imported) to leverage static values in place of the SMA variables for testing.
Best Practice Note As you can see, I’m specifying the variables in what I would call the parent or process Runbook (at the top level). You can then leverage these throughout your nested Runbooks and only require a change at the top most Runbook when required. Each nested Runbook would then receive these defined variables as parameters provided by the parent.
Associate the Runbook into your subscription operations as shown below.
Note Runbooks are associated to events in WAP under the VM CLOUDS custom resource tab and then under AUTOMATION
Additional Note Tagging SPF on the Runbook occurs on the CONFIGURE tab of the Runbook shown above before it will show up as an option in the Runbook dropdown. Only one Runbook for this type of event can be selected (so make it a good one ).
Next, we need a way to send emails to whomever you need to in order to communicate a job starting, completing, failing, etc. This Runbook is called a couple of times in my example to notify the defined SMTP recipients (once on initial notification and once on completion). The idea is that this Runbook can be configured in such a way that it can be used as your general notifying Runbook. Even the subject and body of your email can be parameterized to make this even more flexible of course but will require some rework to make it functional for that scenario. This at least gets you started with a good working model to build from!
The Send-SmtpNotification workflow takes in parameters shown below.
Below you can see an example of the three possible types of notifications you may see. These are shown with some HTML content to pretty it up but you could certainly reduce these to plain text emails. Details were covered briefly in the $SendNotificationType parameter above.
This Runbook is used to monitor for the completion of a SC JOB using the ID and taking in a parameter in seconds to determine the looping intervals. You can easily modify this to adapt to your needs. Consider this an example that you can add your own logic and return values from.
The Monitor-SCJobStatus takes in parameters as shown below
This workflow should output the completion status of the job that was being monitored. This would be specific to the job. (Example: a successful completion of the example job we are monitoring = Complete).
So in summary of all we’ve talked about
Invoke-SubscriptionCreateRunbook: Kicks off an SCJob Send-SmtpNotification: Sends an email Monitor-SCJobStatus: Monitors the SCJob till complete or max time met
Invoke-SubscriptionCreateRunbook: Kicks off an SCJob
Send-SmtpNotification: Sends an email
Monitor-SCJobStatus: Monitors the SCJob till complete or max time met
Until next time – Happy Automating!
And for more information, tips/tricks, and example solutions for SMA, be sure to watch for future blog posts in the Automation Track on http://aka.ms/BuildingClouds!