azure - ARM 模板 webtest 警报规则失败并显示 ResourceNotFound

标签 azure azure-resource-manager

我有一个 Azure 资源管理器模板,它是一组嵌套模板的一部分。它创建一个 App Insights 组件、针对禁止请求的网站的警报规则、多步骤 Web 测试以及针对 Web 测试的警报规则。除针对 Web 测试的警报规则外,所有资源均已成功部署。在部署失败后,我可以进入门户并针对测试创建警报,不会出现任何问题。

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "company": {
        "type": "string"
    },
    "region": {
        "type": "string"
    },
    "retailerAPIKey": {
        "type": "string"
    },
    "deviceID": {
        "type": "string"
    },
    "lumicastVersion": {
        "type": "string"
    }
},
"variables": {
    "frameworkWebSite": "[concat(parameters('company'),'-BLS-FRAMEWORK-',parameters('region'))]"
},
"resources": [
    {
        "name": "[concat('ForbiddenRequests ', variables('frameworkWebSite'))]",
        "type": "Microsoft.Insights/alertrules",
        "location": "[parameters('region')]",
        "apiVersion": "2014-04-01",
        "tags": {
            "displayName": "ForbiddenRequests frameworkWebSite"
        },
        "properties": {
            "name": "[concat('ForbiddenRequests ', variables('frameworkWebSite'))]",
            "description": "[concat(variables('frameworkWebSite'), ' has some requests that are forbidden, status code 403.')]",
            "isEnabled": false,
            "condition": {
                "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
                "dataSource": {
                    "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
                    "resourceUri": "[concat(resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('frameworkWebSite'))]",
                    "metricName": "Http403"
                },
                "operator": "GreaterThan",
                "threshold": 0,
                "windowSize": "PT5M"
            },
            "action": {
                "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
                "sendToServiceOwners": true,
                "customEmails": [ ]
            }
        }
    },
    {
        "name": "[variables('frameworkWebSite')]",
        "type": "Microsoft.Insights/components",
        "location": "Central US",
        "apiVersion": "2014-04-01",
        "tags": {
            "displayName": "Component frameworkWebSite",
            "[concat('hidden-link:',resourceGroup().id,'/providers/Microsoft.Web/sites/',variables('frameworkWebSite'))]": "Resource"
        },
        "properties": {
            "applicationId": "[variables('frameworkWebSite')]"
        }
    },
    {
        "name": "[concat('siteinit-', variables('frameworkWebSite'))]",
        "apiVersion": "2015-05-01",
        "type": "Microsoft.Insights/webtests",
        "location": "Central US",
        "tags": {
            "displayName": "WebtestL ABL BSL Init frameworkWebSite",
            "[concat('hidden-link:', resourceId('microsoft.insights/components/', variables('frameworkWebSite')))]": "Resource"
        },
        "dependsOn": [
            "[concat('microsoft.insights/components/', variables('frameworkWebSite'))]"
        ],
        "properties": {
            "Name": "[concat('GETBytelightInit-',parameters('region'))]",
            "Description": "[concat('GETBytelightInit-',parameters('region'),'.webtest')]",
            "Enabled": true,
            "Frequency": 600,
            "Timeout": 120,
            "Kind": "multistep",
            "Locations": [
                { "Id": "us-il-ch1-azr" },
                { "Id": "us-ca-sjc-azr" },
                { "Id": "us-tx-sn1-azr" }
            ],
            "Configuration": {
                "WebTest": "[concat('<workingwebtest goes here>','<ends here>')]"
            },
            "SyntheticMonitorId": "[concat('siteinit-', variables('frameworkWebSite'))]"
        }
    },
    {
        "name": "[concat('siteinit-', variables('frameworkWebSite'), '-alert')]",
        "type": "Microsoft.Insights/alertrules",
        "apiVersion": "2015-04-01",
        "location": "[parameters('region')]",
        "tags": {
            "displayName": "Alert webtest site  Init frameworkWebSite",
            "[concat('hidden-link:', resourceId('microsoft.insights/components/', variables('frameworkWebSite')))]": "Resource",
            "[concat('hidden-link:', resourceId('microsoft.insights/webtests/', concat('siteinit-', variables('frameworkWebSite'))))]": "Resource"
        },
        "dependsOn": [
            "[concat('microsoft.insights/components/', variables('frameworkWebSite'))]",
            "[concat('microsoft.insights/webtests/siteinit-', variables('frameworkWebSite'))]"
        ],
        "properties": {
            "name": "[concat('siteinit-', variables('frameworkWebSite'), '-alert')]",
            "description": "Alert for site Initialize",
            "isEnabled": true,
            "condition": {
                "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.LocationThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
                "odata.type": "Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition",
                "dataSource": {
                    "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
                    "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
                    "resourceUri": "[resourceId('microsoft.insights/webtests/', concat('siteinit-', variables('frameworkWebSite')))]",
                    "metricName": "GSMT_AvRaW"
                },
                "windowSize": "PT15M",
                "failedLocationCount": 2
            },
            "action": {
                "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
                "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
                "sendToServiceOwners": true,
                "customEmails": [ ]
            }
        }
    }

],
"outputs": {
    "TestLink": {
        "type": "string",
        "value": "[resourceId('microsoft.insights/webtests/', concat('siteinit-', variables('frameworkWebSite')))]"
    }
}

}

部署失败并显示:

"statusMessage": {
  "Code": "ResourceNotFound",
  "Message": "Exception of type 'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' was thrown."
},

这只是此模板中将进行的众多测试中的第一个,每个部署都有 2 个站点副本。因此,手动创建警报规则不是一种选择。

最佳答案

我认为您的resourceUri有问题:

"resourceUri": "[concat(resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('frameworkWebSite'))]",

尝试使用resourceId()函数:

"resourceUri": "[resourceId(resourceGroup().name, 'Microsoft.Web/sites', variables('frameworkWebSite'))]",

参见resourceId() reference here .

希望这有帮助。

关于azure - ARM 模板 webtest 警报规则失败并显示 ResourceNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35587316/

相关文章:

azure - OpenID Connect 使用 Office 365 和 spring security 登录

azure - 如何以编程方式创建 Azure 订阅和 Azure Active Directory

azure - 使用 ARM 模板为 Azure 应用服务配置 Azure AD 身份验证

azure - 使用 ARM 部署将访问策略添加到 key 保管库时如何调试冲突错误

azure - ARM 模板,段长度不正确

git - 如何将 Visual Studio Code 与 Azure GIT Repo 连接

windows - Jenkins Azure Blob 存储插件,用于将 Build 文件夹的内容而不是构建文件夹的内容复制到 $web azure blob static cotainer

c# - Azure 搜索合并索引操作返回异常

c# - 将文件流式传输到 Azure Blob 存储?

azure - 在 ARM 模板中添加私有(private) nuget feed 的身份验证