如何使用ARM模板为Azure资源创建活动日志诊断设置

问题描述 投票:1回答:1

我们正在参考此文档here,该文档讨论了使用Resource Manager模板在Azure中创建诊断设置

我们已经设法通过ARM模板以及资源日志的诊断设置来配置资源,但是,由于模板部署命令(new-azresourcegroupdeployment)返回Bad,因此文档中用于启用activity logs诊断设置的代码片段似乎不起作用请求错误。

New-AzResourceGroupDeployment:资源Microsoft.Insights / diagnosticSettings'test-vnet'失败,消息为'{“代码”:“ BadRequest”,“信息”: ””}'

这里是模板(为避免干扰,整理了一些代码)

{  
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
   ...
},
"variables": {
    ...
},
"resources": [
    {
        "apiVersion": "2018-08-01",
        "type": "Microsoft.Network/virtualNetworks",
        "name": "[parameters('virtualNetworkName')]",
        "location": "[parameters('resourceLocation')]",
        "properties": {
            "addressSpace": {
                "addressPrefixes": [
                    "[parameters('addressPrefix')]"
                ]
            },
            "subnets": "[parameters('subnets')]",
            "dhcpOptions": {
                "dnsServers": "[parameters('dnsServers')]"
            }
        },
        "resources":
        [
            {
                "type": "Microsoft.Insights/diagnosticSettings",
                "apiVersion": "2017-05-01-preview",
                "name": "[variables('diagnosticsSettingsName')]",
                "dependsOn": [
                    "[parameters('virtualNetworkName')]"
                ],
                "location": "global",
                "properties": 
                 {
                    "storageAccountId": "..valid_id_here",
                    "logs": 
                    [
                        {
                            "category": "Administrative",
                            "enabled": true
                        },
                        {
                            "category": "Security",
                            "enabled": true
                        },
                        {
                            "category": "ServiceHealth",
                            "enabled": true
                        },
                        {
                            "category": "ResourceHealth",
                            "enabled": true
                        }
                    ]
                }
            }
        ]
    }
],
"outputs": {
    ..
}
azure azure-resource-manager arm-template azure-virtual-network azure-diagnostics
1个回答
2
投票

创建诊断设置所参考的文档here。>>

因此,如果您要检查本文档中的Deployment Methods,它表示您可以使用任何有效的方法(包括PowerShell和CLI)来部署资源管理器模板。 活动日志的诊断设置必须使用CLI的az deployment create或PowerShell的New-AzDeployment部署到预订中。>

使用New-AzDeployment代替New-AzResourceGroupDeployment

来部署ARM模板。

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.