我已经编写了一个脚本,该脚本将启用或禁用所有的天蓝色警报(日志分析警报),但是当我禁用应用程序洞察警报时,它会被禁用,但是当禁用在日志分析工作区上创建的警报时,它会给出以下错误提示
Disable-LogAnalyticsAlertRule:{“错误”:{“代码”:“ PatchResourceNotFound”,“消息”:“资源'https://management.az ure.com/subscriptions/4776c051-f4ef-4a30-8ce7-c9fb99ff0fc5/resourcegroups/DevOpsTestRG-A/providers/microsoft.insights/s 执行PATCH操作时找不到cheduledQueryRules / nameofthealert?api-version = 2018-04-16'。“}} 在C:\ Users \ Temenos \ Desktop \ disable.ps1:1 char:1 +禁用LogAnalyticsAlertRule + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:未指定:(:) [Write-Error],WriteErrorException + FullyQualifiedErrorId:Microsoft.PowerShell.Commands.WriteErrorException,Disable-LogAnalyticsAlertRule
Disable-LogAnalyticsAlertRule { 参数( [string] $ ResourceGroupName, [string] $ Rulename) $ headers = Get-AccessTokenFromContext $ cur_sub =(Get-AzureRmContext).Subscription.Id $ ruleUri =“ https://management.azure.com/subscriptions/ $ cur_sub / resourcegroups / $ resourceGroupName / providers / microsoft.insights / scheduledQueryRules / $ RuleName” +“?api-version = 2018-04-16” $ bodyEnable =“ { '属性':{ '启用':'假' } } ” 详细写入“正在调用的ResourceURI:$ ruleUri” 尝试{ $ disablerule =调用RestMethod-方法PATCH -Uri $ ruleUri -Headers $ headers -Body $ bodyEnable $ disablerule |选择对象@ {Name =“ displayName”; Expression = {$ .properties.displayName}},@ {Name =“ IsEnabled”; Expression = {$ .properties.enabled}},@ { Name =“ lastUpdate”; Expression = {$ .properties.lastUpdatedTime}},@ {Name =“ provisioningState”; Expression = {$ .properties.provisioningState}} |格式表-AutoSize-换行 详细写入“ Invoke-RestMethod的输出:$ disablerule” } 抓住 { 写错误“ $ _” } }
实际结果是必须禁用通过loganalytics创建的警报