首页 > 解决方案 > 当我部署我的 Azure ARM 模板时,它会创建一个存储,而不是一个警报

问题描述

我为警报创建了一个 Azure 模板,因为我想同时上传带有新微服务的脚本 (.json)。但是如果我部署这个 .json 文件,它会创建一个新的存储,而不是一个警报。我使用了 Powershell 命令New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile c:\MyTemplates\storage.json -storageAccountType Standard_GRS。在我的模板中,我需要定义参数kind,它只能接受值为Storageor Blobstorage,但我不想要这两个。那么我如何通过使用脚本 .json 文件来创建警报,并且是否有人有模板,因为 MS 没有提供正确的模板。

编辑:这是 .json 文件:

{
"$schema":
"http://schema.management.azure.com/schemas/2015-01- 
01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
  "name": "[concat('storage', uniqueString(resourceGroup().id))]",
  "type": "Microsoft.Storage/storageAccounts",
  "apiVersion": "2016-01-01",
  "sku": {
    "name": "Standard_LRS"
  },
  "kind": "Storage",
  "id":
    "/subscriptions/subscriptionID/resourceGroups/resourceGroupName/providers/Microsoft.Storage/storageAccounts/storageName",
  "location": "westeurope",
  "properties": {
    "name": "tryAgain",
    "description": null,
    "isEnabled": true,
    "condition": {
      "$type":
        "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
      "odata.type":
        "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
      "dataSource": {
        "$type":
          "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
        "odata.type":
          "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
        "resourceUri":
          "/subscriptions/subscriptionID/resourcegroups/resourceGroupName/providers/microsoft.web/sites/name",
        "resourceLocation": null,
        "metricNamespace": null,
        "metricName": "AverageMemoryWorkingSet",
        "legacyResourceId": null
      },
      "operator": "GreaterThanOrEqual",
      "threshold": 120000000,
      "windowSize": "PT10M",
      "timeAggregation": "Average"
    },
    "actions": [
      {
        "$type":
          "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleWebhookAction, Microsoft.WindowsAzure.Management.Mon.Client",
        "odata.type":
          "Microsoft.Azure.Management.Insights.Models.RuleWebhookAction",
        "serviceUri":
          "Logic-app URL",
        "properties": {
          "$type":
            "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary`1[[System.String, mscorlib]], Microsoft.WindowsAzure.Management.Common.Storage",
          "logicAppResourceId":
            "/subscriptions/subscriptionID/resourceGroups/Default-Storage-WestEurope/providers/Microsoft.Logic/workflows/Microsoft-Teams-Notifier"
        }
      }
    ]
  }
}
]
}

标签: jsonazureazure-template

解决方案


有关通过 Azure 资源管理器模板创建指标警报的信息,请参阅以下参考。如果要创建单个 ARM 模板来创建存储帐户,然后创建度量警报来监视创建的存储帐户,则应确保具有 dependsOn 以便仅在存储帐户之后创建警报规则。以下文档引用了较新的指标警报,而不是经典指标警报。

https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-create-metric-alerts-with-templates


推荐阅读