In Microsoft Azure, events are constant, and it’s important to stay on top of them. Azure has a service called Azure Monitor that allows an administrator to keep tabs on actions in Azure. Azure Monitor contains a feature called action groups, and action groups allow an administrator to group various events and alerts together to fire when a trigger event occurs.
In this article, we’ll see what it takes to create and configure an action group in Azure — not in the portal, but with PowerShell!
To get started, you’ll first need to log into your Azure portal and go to Monitor –> Alerts. Notice we have the option to manage action groups here. You’ll also see that we already have one action group set up.
You’ll notice that we’ve already got one action group set up.
We could go to Add action group at the top and create a new action group, but for this example, I’m going to do it in PowerShell. So if we go over to our PowerShell code, the first thing we need to do is make sure we’re connected to Azure by running: Connect-AzureRmAccount.
Next, if we run the Get-AzureRMActionGroup command below, we’ll see that it lists the name of the action group that we’ve already created.
Get-AzureRmActionGroup | Select-Object Name
To create a new action group, we’re going to use the New-AzureRmActionGroup receiver command to set up a new receiver. I’m going to give it a name and call it NotifyFrank. And we’re going to set this up as an email receiver. So if we look at the options in Visual Studio Code, we have EmailReceiver, we have SMSReceiver, we have WebhookReceiver, etc.
We could choose any of these, but for this example, I’m going to select EmailReceiver.
I’m also going to need to give it an email address. So I’m going to give it Frank’s email address. And I’m going to pipe this all into a variable for use later on, as shown below.
$FranksEmail = New-AzureRmActionGroupReceiver -Name NotifyFrank -EmailReceiver -EmailAddress ‘firstname.lastname@example.org‘
Next, I’d like to set up a notification to Frank’s SMS as well. For this example, I will do this by making the receiver an SMS receiver and give it the CountryCode and a PhoneNumber for the SMS to be sent out.
$FranksSMS = New-AzureRmActionGroupReceiver -Name ‘FranksSMS’ -SmsReceiver -CountryCode ’44’ -PhoneNumber ‘5555555555’
Once we have these two variables, we can then use the Set-AzureRmActionGroup command to create the new action group. To do this, we need to give it a name. I’m going to call it Notifyfrank. We then need to give it a resource group and a short name. Finally, we feed it the two receivers that we created earlier.
Set-AzureRmActionGroup -Name ‘NotifyFrank’ -ResourceGroupName ‘MattBrowne_RG’ -ShortName ‘Frank’ -Receiver $FranksEmail, $FranksSMS
If we then run Get-AzureRmActionGroup, we should see that we now have two action groups created.
And if we go back to the Azure console and refresh it, we now have our new action group called NotifyFrank.
That’s all there is to creating action groups in Azure with PowerShell!