Azure Automation – Up / Down Scale Azure VM

car

Recently I made a couple of demos how you could benefit from Azure Automation acting on certain alerts. One demo was, if an OMS or Azure Monitor alert is triggered because of high CPU on your Azure VM, a webhook will be called and scale up the Azure VM to a predefined size.

webhook-alert

In Azure Monitor you are able to create an Alert and set the threshold to e.g. 80%…

image

…and then call a webhook…

image

Note: Azure Monitor has already built-in alert action to start / stop a virtual machine or even scale up / down. These actions install and call pre-configured Azure Automation runbooks from Microsoft. But this post should show you in a transparent way how you can achieve it, doing it yourself.

As you probably know in OMS you are also able to provide a webhook in your alert settings…

image

Which ever way you choose Azure Monitor or OMS, it does not matter. I just want to provide you the PowerShell script I used in Azure Automation. Although it is far from complete and production level, but as demo it serves it’s purpose Smile.

# Get automation credential for authenticating and resizing the VM
$Credential = Get-AutomationPSCredential -Name 'AzureScaleUser'
# Size of the VM like Standard_D1_v2, Standard_D2_v2
$HWProfile = Get-AutomationVariable -Name 'ScaleUpSize'
# Resource group where the VM is living in
$ResourceGroup = Get-AutomationVariable -Name 'ResourceGroup'
# Subscription which hosts the VM / account etc.
$SubscriptionId = Get-AutomationVariable -Name 'SubscriptionID'
# VM name you want to up / down scale
$VMName = Get-AutomationVariable -Name 'VMName'
# Login to azure
Add-AzureRMAccount -Credential $Credential  -SubscriptionId $SubscriptionId
# Get the VM
$VM = Get-AzureRmVM -Name $VMName -ResourceGroupName $ResourceGroup

If ($VM.HardwareProfile.VmSize -eq $HWProfile)
 {
     Write-Output "HW size already set to $($VM.HardwareProfile.VmSize)"
 }
 Else
 {
     Write-Warning "Scaling up to $HWProfile"
	 # Set new VM size
     $VM.HardwareProfile.VmSize = $HWProfile
	 # Update VM
     Update-AzureRmVM -VM $VM -ResourceGroupName $ResourceGroup
     Write-Output "HW scaling up to $($VM.HardwareProfile.VmSize)"
 }

My Azure Automation variables look like this…

image

I hope this helps you for your next demo / PoC or what ever project you need it for.

Experts Live Europe – Speaker

ExpertsLive_EUROPE_pos_blue_rgb

Once more I am very excited to be part of one of the best IT conferences in Europe – Experts Live Europe. The 3 conference days are taking place from August 23 – 25 in the Berlin Congress Center in Berlin Germany and will bring together the Microsoft IT Pro Community from all over the world, including a large quantity of Microsoft MVPs and (former) Microsoft employees. You will get the latest about datacenter, cloud and workplace trends. This also includes many vertical topics such as security, identity management and much more.

I will have several sessions / discussion panels / demos:

Azure TestDev Labs – What the heck is it?
Wednesday, August 23 • 10:45am – 11:45am
In this session we, my wingman MVP Stefan Johner and I, show you how you can use Azure DevTest Labs to build your own lab and keep control of cost and resources.

Discussion Panel: Insights and Analystics
Wednesday
, August 23 • 3:15pm – 4:15pm
Discussion panels allow you to meet a group of experts and discuss your questions. In this panel my buddy MVP Kevin Greene and I would like to discuss about OMS monitoring and mainly about Insights and Analytics.

The best of the SCOM community (+whisky tasting)
Wednesday, August 23 • 4:45pm – 5:45pm
If you haven’t been to this famous Squared Up session in the past years, you definitely missed something. Squared Up will present their latest and greatest news about their products surrounded with delicious whisky tasting. There will be some room for community presentations about their recently released PowerShell MP. I will also have a short entertaining demo, what you can do with this MP and PowerShell.

Azure Monitor & Co
Friday, August 25 • 8:00am – 9:00am
Monitoring Azure is getting more and more important. This session will give you an overview of Azure Monitor and its best buddies. I will show you the basics and how you could make sense out of your data.

On-premise automation using SCSM, SMA and PowerShell
Friday, August 25 • 2:00pm – 3:00pm
Everyone is talking about automation. But what does that mean if business processes or IT infrastructures are automated on-premise? Microsoft offers System Center Service Manager (SCSM), Service Management Automation (SMA) und PowerShell as core components to achieve the goal. MVP Stefan Roth and Jonas Feller talk about what problems you could face and what impact does it have starting such a project. In addition we show you a current real-world case and talk about experiences we have made in the past.

me2

I am convinced that this will be another legendary edition of Experts Live Europe and I hope to see you there. If you are not familiar with Experts Live Europe at all read MVP Marcel Zehner’s blog post.


OMS – Azure Scheduler Solution

Bildergebnis für Azure Scheduler logo

UPDATE 07.08.2017 21:51: I found a bug in the ARM template which made the dashboard not appearing. I fixed it just now, in case you deployed the solution, just redeploy it. Sorry for that hassle.

Currently I am doing some more OMS stuff and therefore I also took a deeper dive at building ARM templates to deploy an OMS solution. I was looking for a simple Azure service to gather data from, which I could ingest into OMS. My goal was, to have a use case, where I only need to provide the minimal parameters necessary and the rest should be done by the ARM template.

How does it work?

Well, basically there is Azure Automation which runs a PowerShell script on an hourly schedule to collect data from Azure Scheduler service. If there are any collections and jobs in Azure Scheduler it will ingest the data into OMS via API.

The OMS solution will contains the following views:

  • Jobs with errors
  • Status of the jobs
  • Jobs and how many times it has been executed
  • How many jobs a collection contains
  • Some useful queries

OMSAzureScheduler

How do I deploy it?
Go to my https://github.com/stefanrothnet/AzureScheduler

image

You need to provide the credentials to access Azure Scheduler service, these will be saved in the Azure Automation account. Make sure the credentials have permission to access the subscription you are accessing. In addition you need to provide a schedule link GUID. Because there is no function in ARM template to generate a GUID, we need manually to provide a GUID. This GUID is needed to link the Azure Automation schedule to the Azure Automation runbook. Use PowerShell cmdlet New-Guid to generate a GUID and paste it into to the settings.

image

The template does the following steps:

  • Creates a resource group
  • Creates an Azure Automation account
  • Deploys the PowerShell runbook / script to collect Azure Scheduler data
  • Creates an Azure Automation schedule to run the runbook to collect the data. It starts every one hour starting at deployment.
  • Creates an Azure Automation variables for OMS workspace and key
  • Creates an Azure Automation  variable for the current subscription id
  • Creates an Azure Automation credential with username and password
  • Updates the AzureRM.Profile and AzureRM.Scheduler modules
  • Installs the OMSIngestionsAPI module
  • Deploys an OMS workspace and installs the solution into the workspace

If you have tried to create such a solution before or any other ARM project, you know, there are many problems you will face.

So what is the current state of this solution?

  • All the necessary components are being deployed and are working (I tested it only in the West Europe Azure location!)
  • There are some parts with the OMS dashboard I need to update and adjust, but for the moment it works and offers a good demo case for an OMS solution.
  • Be aware, it is not a production ready product, it is made for learning and testing. I tested it only briefly and I am not an Azure Scheduler MVP 😉 .

If you encounter any problems or things that don’t appear the way they should, let me know. Have fun!

Quick Post – Azure Services Overview

There is a saying “Can’t see the forest for the trees” this could also apply to Azure and its provided services. I haven’t seen a good overview of Azure and the offered services until today. While browsing the internet, I bumped into this site here http://azureplatform.azurewebsites.net/en-us/ . image

It is an interactive site which shows the single services in each category and provides links to more information like updates, pricing, SLA, documentation etc. image

I love this page and I highly recommend to explore and bookmarking it! It is even available in German :).

Quick Post – Linux + PowerShell + DSC Blog Posts @ Hey, Scripting Guy! Blog

image

I would like to make you aware of a 3-part blog post series, which I have written for THE Microsoft Hey, Scripting Guy! Blog .  Because I really like these blog post series and of course the blog itself a lot , I want to share it with you.

The first part shows you, how to use Bash on Windows 10 and how you can connect to a Linux server to install OMI CIM server and the DSC for Linux packages. The second part installs .NET Core and PowerShell for Linux on the system using DSC for Linux. In addition, I show you how to connect via PowerShell and WSMan protocol from your Windows 10 to the OMI CIM server. The last post is applying a DSC configuration from Azure Automation DSC to Linux and executing a PowerShell script to send user data to Azure Log Analytics HTTP Data Collector API .

You can find the post here:

Part 1 – Install Bash on Windows 10, OMI CIM Server, and DSC for Linux

Part 2 – Install .NET Core and PowerShell on Linux Using DSC

Part 3 – Use Azure Automation DSC to Configure Linux and Executing PowerShell Script

 

I hope you like it as much as I do, have fun!

MS Flow – Trigger Azure Automation Webhook

In one of my previous post I showed you how you could trigger a webhook to trigger an Azure Automation runbook using IFTTT (If This Than That) . Well, the great news are that Microsoft is investing a great deal of money into a similar technology called Microsoft Flow. For a short summary and differences to other task automation engines see this post here. In Microsoft Flow there is also a way to trigger a webhook similar to IFTTT, it works like this…

image

…in this template I used Twitter as a starting activity, but you can use any other. I used the Http activity and configured it like this Method => POST and Uri => copy and paste the webhook URI from your Azure Automation runbook. Within the body I used previous data from Twitter like who tweeted and tweet text. If you are new to webhooks, there is an excellent documentation here. 

The webhook data will look something like this…

image

As you can see it is very easy to trigger an Azure Automation runbook via MS Flow. The very cool thing of MS Flows is, it’s tight integration into the Microsoft products. Although MS Flow is in preview, there are quite some templates available for automating your daily (business) tasks. Have fun!

Azure Automation – Twitter + IFTTT + Webhook = Start Runbook

image

I assume you know Twitter and you probably also know what a webhook is, right? No? Ok, a webhook is just a HTTP POST. In Azure Automation we are able to create a webhook for a runbook. This runbook will “consume” the webhook request  (URL) + post data and start the runbook. The cool thing is, that you are able to trigger a runbook in a secure way without the need of credentials and you are able to pass parameters within this request. Well, this is nothing special in todays world, but sometimes the combination of things make the magic.

Another technology, which has been around for a few years is IFTTT (If This Than That), this is a online service that let’s you choose a channel A (trigger) and if a certain condition happens it will trigger channel B (action). For example channel A could check the weather in Switzerland (because you are planning a trip to Switzerland) and if it will start raining you could trigger channel B to receive a warning by email. This combination of channels is called a “recipe”. You can choose from dozens of channels and combine them as you like. I highly recommend to check this service out, it is easy and fun.

In this post I want to show how to trigger a webhook / runbook, if someone is tweeting about SCOM.

Continue reading