gpt4 book ai didi

Azure 监视器警报多个订阅

转载 作者:行者123 更新时间:2023-12-02 07:19:19 24 4
gpt4 key购买 nike

我需要创建多个 azure 监视器警报。我正在尝试按照此网站执行此操作: https://www.azureblue.io/how-to-create-an-alert-rule-using-powershell-and-azure-cli/

如果我在同一订阅中有操作组和目标资源,则此解决方案适合我,但通常情况下我没有。我在近 100 个订阅中有一个操作组和数百个目标。

我有:

#jump to subscription with actiongroup
$context = Get-AzSubscription -SubscriptionId xxx
Set-AzContext $context

$actionGroup = Get-AzActionGroup -name "xxx" -ResourceGroupName "xxx"
$actionGroupId = New-AzActionGroup -ActionGroupId $actionGroup.Id

#jump to subscription with target without this I can't ask for target.id
$context = Get-AzSubscription -SubscriptionId xx
Set-AzContext $context

# Creates a local criteria object that can be used to create a new metric alert
$condition = New-AzMetricAlertRuleV2Criteria `
-MetricName "Data space used percent (Platform)" `
-TimeAggregation Maximum `
-Operator GreaterThan `
-Threshold 0.8

$windowSize = New-TimeSpan -Minutes 30
$frequency = New-TimeSpan -Minutes 5
$targetResourceId = (Get-AzResource -Name xxx).Id

#I was thinking that this jump to subscription will solve my issue but doesn't
$context = Get-AzSubscription -SubscriptionId cf653672-c304-49a2-b01b-171f6236bad6
Set-AzContext $context

# Adds or updates a V2 (non-classic) metric-based alert rule.
Add-AzMetricAlertRuleV2 `
-Name "test" `
-ResourceGroupName "xxx" `
-WindowSize $windowSize `
-Frequency $frequency `
-TargetResourceId $targetResourceId `
-Condition $condition `
-ActionGroup $actionGroupId `
-Severity 3

我收到此错误:

Add-AzMetricAlertRuleV2 : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:NotFound, Reason phrase: Not Found
At line:26 char:1
+ Add-AzMetricAlertRuleV2 `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzMetricAlertRuleV2], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Alerts.AddAzureRmMetricAlertRuleV2Command

从 GUI 中,从不同订阅中选择操作组没有问题,但无法从多个订阅中选择目标。

如果我能找到此示例的解决方案,我将尝试读取所有资源并循环运行代码。

最佳答案

我最近遇到了这样的错误..这是由于输入无效造成的。在我的特定情况下,这是由于alertName中的无效字符造成的。

至于多重订阅的主要问题...

这里有一些想法:

  1. 同时将单个指标警报应用于相同类型的多个资源。您可以使用 Add-AzMetricAlertRuleV2 指定范围、区域等,请参阅: https://learn.microsoft.com/en-us/powershell/module/az.monitor/add-azmetricalertrulev2?view=azps-7.2.0 。这仅限于少数资源 https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-metric-overview#monitoring-at-scale-using-metric-alerts-in-azure-monitor .

请注意,TargetResourceScope 是一个字符串数组。因此,理论上似乎可以将警报应用于多个订阅。

  • 当其他选项不可行时:使用 Get-AzSubscription,并将代码部署到每个订阅或获取运行代码所需的订阅列表。
  • 您的单一操作组。

    我可以验证,您可以为订阅内的任何警报设置一个操作组。如果 actiongroup.id 正确且不存在 RBAC/防火墙问题,我看不出操作组不能位于单独订阅中的任何原因。但我没有办法测试这一点。

    最后,这是 MS 论坛中的相关对话。 https://techcommunity.microsoft.com/t5/azure-monitor/azure-monitor-multiple-subscriptions/m-p/1348362

    关于Azure 监视器警报多个订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69839258/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com