Hi @Akash Chopra ,
Thanks for posting this question in Microsoft Q&A platform and for using Azure services.
As I understand from the question, you need a PowerShell script for enabling alerts for all PaaS resources in Azure.
Please check below if this helps in your use-case:
[CmdletBinding()]
param (
# ResourceGroup to operate on.
[Parameter(Mandatory=$true)]
[string]
$ResourceGroupName,
<# Switch parameter to either enable or disable all rules, default value
is false if not supplied when calling the script. #>
[switch]
$Enable
)
# Get all the rules for the given Resource Group.
$alertRules = @(Get-AzureRmAlertRule -ResourceGroupName $ResourceGroupName);
<# Function reads the array and enables all rules in the array. If a rule is already enabled,
it will stay enabled. #>
function Enable-AllRules {
param([string]$RG)
foreach ($rule in $alertRules) {
Add-AzureRmMetricAlertRule `
-ResourceGroupName $RG `
-TargetResourceId $rule.Condition.DataSource.ResourceUri `
-Location $rule.Location `
-Name $rule.AlertRuleResourceName `
-Description $rule.Description `
-MetricName $rule.Condition.DataSource.MetricName `
-Operator $rule.Condition.OperatorProperty `
-Threshold $rule.Condition.Threshold `
-WindowSize $rule.Condition.WindowSize `
-TimeAggregationOperator $rule.Condition.TimeAggregation;
}
}
switch ($Enable) {
$true { Enable-AllRules -RG $ResourceGroupName; }
Default { Disable-AllRules -RG $ResourceGroupName; }
}
Please let us know if this answers your question. If not, please reply so that we can help further.
------------------------------
- Please don't forget to click on
or upvote
button whenever the information provided helps you.
Original posters help the community find answers faster by identifying the correct answer. Here is how - Want a reminder to come back and check responses? Here is how to subscribe to a notification