gpt4 book ai didi

azure - 使用 Powershell Azure ARM 启用/禁用 AppInsights 可用性测试

转载 作者:行者123 更新时间:2023-12-04 22:48:17 31 4
gpt4 key购买 nike

简单的问题,尝试使用 Powershell Azure ARM 禁用/启用我的 Application Insights 可用性测试。我们已经安排了服务器的重启,我想把这些时间划掉,这样我们就不会记录错误。

我尝试了以下方法

$alert = Get-AzureRmAlertRule -ResourceGroupName $resourceGroup `
| Where-Object {$_.Name -like '*isalive*'} `
| Where-Object {$_.Name -like "*$vmName*"}


Add-AzureRmWebtestAlertRule -Name $alert.Name `
-Location $alert.Location `
-ResourceGroupName $resourceGroup `
-WindowSize $alert.Condition.WindowSize `
-MetricName $alert.Condition.DataSource.MetricName `
-TargetResourceUri $alert.Id `
-FailedLocationCount $alert.Condition.FailedLocationCount `
-DisableRule `
-Verbose

https://learn.microsoft.com/en-us/powershell/module/azurerm.insights/add-azurermwebtestalertrule?view=azurermps-6.8.1

但是我回来了

WARNING: 3:34:18 PM - The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.

WARNING: 3:34:18 PM - The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.

VERBOSE: Performing the operation "Create/update an alert rule" on target "Create/update an alert rule: azecdag02 isalive-sitecore production-2c06a496-3567-4871-a57c-2c516c0ccfef from resource group: OAT_Website".

VERBOSE: 3:34:18 PM - CreateRuleCondition: Creating location threshold rule condition (webtest rule)

VERBOSE: 3:34:18 PM - CreateSdkCallParameters: Creating rule object

Add-AzureRmWebtestAlertRule : Exception type: ErrorResponseException, Message: The setting already exists., Code: SettingAlreadyExists, Status code:Conflict, Reason phrase: Conflict At line:1 char:1 + Add-AzureRmWebtestAlertRule ` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Add-AzureRmWebtestAlertRule], PSInvalidOperationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Alerts.AddAzureRmWebtestAlertRuleCommand

如果我尝试Resolve-AzureRmError -Last我得到

HistoryId: 80

Message : Exception type: ErrorResponseException, Message: The setting already exists., Code: SettingAlreadyExists, Status code:Conflict, Reason phrase: Conflict StackTrace : at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : System.Management.Automation.PSInvalidOperationException InvocationInfo : {Add-AzureRmWebtestAlertRule} Line : Add-AzureRmWebtestAlertRule ` Position : At line:1 char:1 + Add-AzureRmWebtestAlertRule + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 80

Message : Operation returned an invalid status code 'Conflict' StackTrace : at Microsoft.Azure.Management.Monitor.AlertRulesOperations.d__5.MoveNext() Exception : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException InvocationInfo : {Add-AzureRmWebtestAlertRule} Line : Add-AzureRmWebtestAlertRule ` Position : At line:1 char:1 + Add-AzureRmWebtestAlertRule + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 80

最佳答案

我终于能够让它工作了,请参阅下面的脚本。

https://feedback.azure.com/forums/357324-application-insights/suggestions/16304431-possibility-to-enable-disable-availability-web-tes

#later versions of AzureRM don't support Find
#Get-AzureRmResources -ResourceGroupName "My_Website"
$allAlerts = Find-AzureRmResource -ResourceGroupNameEquals "OAT_Website" `
| Where-Object -Property ResourceType -EQ "microsoft.insights/webtests" ;





$vmPrefix = "azesc"
$color = "blue"
$status = "True"
$alertIDs = $allAlerts | Where-Object {$_.Name -like "*$vmPrefix*" -or $_.Name -like "*$color*" } `
| Select-Object -ExpandProperty ResourceId


ForEach ($alertID in $alertIDs) {

$alert = Get-AzureRMResource -ResourceId $alertID
$alert.Properties.Enabled = $status
$alert | Set-AzureRMResource -Force
}




$vmPrefix = "azec"
$color = "green"
$status = "False"
$alertIDs = $allAlerts | Where-Object {$_.Name -like "*$vmPrefix*" -or $_.Name -like "*$color*" } `
| Select-Object -ExpandProperty ResourceId


ForEach ($alertID in $alertIDs) {

$alert = Get-AzureRMResource -ResourceId $alertID
$alert.Properties.Enabled = $status
$alert | Set-AzureRMResource -Force
}

关于azure - 使用 Powershell Azure ARM 启用/禁用 AppInsights 可用性测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52264529/

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