Jump to content

Create Azure Service Health Alerts for All Resource Groups


Recommended Posts

Guest wernerrall
Posted

Introduction

 

I recently had a customer requirement for creating Azure Service Health Alerts. The way access was provided in Azure, meant that only specific users had access to their respective Resource Groups. We also did not want these users to receive alerts for all Resources in the Subscription [Default scope for Service Health Alerts].

 

 

 

Process Description:

 

This led to the creation of a PowerShell Script that will cycle through each Resource Group and create Service Health Alerts for all Contributors or Owners.

 

 

Script Explanation

 

*Please only run this script in PowerShell 7 and above as I am using the -Parallel switch

 

  1. Breaking the script into a few different sections, we will start by connecting to Azure and getting a list of all subscriptions

 

 

 

largevv2px999.png.b8298a7814a4c5c3840c52c2728162d7.png

 

 

 

  1. Then we will kick off a few Parallel processes to speed things up. These jobs will change context for each subscription and then find all resource groups

 

 

 

largevv2px999.png.c504522694fcd3b14e8db143c17c3968.png

 

 

 

  1. Now we will find all Contributors on the resource group. If there are none we will look for Owners. We are only looking for objects that have a SignInName as we will need that for our email address assignment.

 

 

 

largevv2px999.png.f37c4697b4f304647669cc3f800875f1.png

 

 

 

  1. By using the ARM Template for Health Alerts we can create a deployment with some parameters which I am randomizing the numbers for.

 

 

 

largevv2px999.png.4abdaa693e4309966c0533d3fcd0c974.png

 

 

 

  1. If we take a closer look at the ARM Template one of the original problems were that this could only be assigned to the subscription().id scope

 

 

 

largevv2px999.png.af71d449a9014ec22bfd448725f2af37.png

 

 

 

 

 

But by added two new parameters and modifying the scope I could get it to apply on ResourceGroup Level

 

 

 

largevv2px999.png.7ef6e643ba58c55dbb9ece0fdc0fb551.png

 

 

 

 

 

Running the Script

 

 

 

  1. Simply grab the PowerShell from my GitHub Repo and save it into a PS1 file.

 

 

 

largevv2px999.png.042aa8ff7b7f0dde03fb1d613c101879.png

 

 

 

 

 

  1. Launch a PowerShell 7 or newer session, change directory to your ps1 file and run.

 

 

 

largevv2px999.png.1fe0562444177fa5f11e96404cded7a1.png

 

 

 

 

 

  1. The PowerShell session will launch an Azure Window to Authenticate you

 

 

 

largevv2px999.png.6bdf2f05f78be5c4bc1b7c2407c519a8.png

 

 

 

 

 

largevv2px999.png.32caf22b70c1c1f5078416b8354ed16d.png

 

 

 

You might see some warnings as I am not hiding any errors.

 

 

 

largevv2px999.png.64facb4c702637075652811c0527c4fc.png

 

 

 

On Success you should see the ARM Template deployed.

 

 

 

largevv2px999.thumb.png.33a555675d7fce1457c805c3a7d66b31.png

 

 

 

We can confirm the deployment ran by looking in the deployments section of the resource group

 

 

 

largevv2px999.png.3cf36b012067e4cccfe8001802e22598.png

 

 

 

largevv2px999.png.13f45559453b5f9c2fccf25745dd7d00.png

 

 

 

Also if we go into Service Heath and click on Health Alerts we will see all our newly created alerts.

 

 

 

largevv2px999.png.8d2bc54ca29e86eabadfddcabe1e51bd.png

 

 

 

Find a copy of my code RallTheory/CreateServiceHealthAlertsForMyResources at main · WernerRall147/RallTheory

 

 

 

Disclaimer

 

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts or Power BI Dashboards are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts or Power BI Dashboards be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...