0

我创建了一个策略来修复未启用诊断设置(经典)日志的存储帐户。但是我收到了这个错误:

{"code":"DeploymentFailed","message":"至少一项资源部署操作失败。请列出部署操作以了解详细信息。请参阅https://aka.ms/arm-debug了解使用详情。","详细信息":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"InvalidTemplate\",\r\n \ "message\": \"无法处理资源 '/subscriptions/providers/Microsoft.Insights/diagnosticSettings/StorageLogs' 的第 1 行和第 429 列的模板语言表达式。'找不到模板参数'logAnalytics'。有关使用详情,请参阅https://aka.ms/arm-template/#parameters。'\",\r\n \"

{
    "properties": {
        "displayName": "Deploy Diagnostic Settings for Storage Accounts to Log Analytics",
        "mode": "Indexed",
        "description": "Deploys the diagnostic settings for Storage Accounts to log read/write/delete and retain logs.",
        "metadata": {
            "category": "Monitoring"
        },
        "parameters": {
            "effect": {
                "type": "String",
                "metadata": {
                    "displayName": "Effect",
                    "description": "Enable or disable the execution of the policy"
                },
                "allowedValues": [
                    "DeployIfNotExists",
                    "Disabled"
                ],
                "defaultValue": "DeployIfNotExists"
            },
            "profileName": {
                "type": "String",
                "metadata": {
                    "displayName": "Profile Name",
                    "description": "The diagnostic setting profile name"
                },
                "default": "setbypolicy_logAnalytics"
            },
            "logAnalytics": {
                "type": "String",
                "metadata": {
                    "displayName": "Log Analytics workspace",
                    "description": "Select Log Analytics workspace from dropdown list. If this workspace is outside of the scope of the assignment you must manually grant 'Log Analytics Contributor' permissions (or similar) to the policy assignment's principal ID.",
                    "strongType": "omsWorkspace",
                    "assignPermissions": true
                }
            },
            "metricsEnabled": {
                "type": "String",
                "metadata": {
                    "displayName": "Enable metrics",
                    "description": "Whether to enable metrics stream to the Event Hub - True or False"
                },
                "allowedValues": [
                    "True",
                    "False"
                ],
                "defaultValue": "False"
            },
            "logsEnabled": {
                "type": "String",
                "metadata": {
                    "displayName": "Enable logs",
                    "description": "Whether to enable logs stream to the Event Hub - True or False"
                },
                "allowedValues": [
                    "True",
                    "False"
                ],
                "defaultValue": "True"
            }
        },
        "policyRule": {
            "if": {
                "field": "type",
                "equals": "Microsoft.Storage/storageAccounts"
            },
            "then": {
                "effect": "[parameters('effect')]",
                "details": {
                    "type": "Microsoft.Insights/diagnosticSettings",
                    "name": "[parameters('profileName')]",
                    "existenceCondition": {
                        "allOf": [
                            {
                                "field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
                                "equals": "parameters('logsEnabled')"
                            },
                            {
                                "field": "Microsoft.Insights/diagnosticSettings/metrics.enabled",
                                "equals": "parameters('metricsEnabled')]"
                            }
                        ]
                    },
                    "roleDefinitionIds": [
                        "/providers/Microsoft.Authorization/roleDefinitions/"
                    ],
                    "deployment": {
                        "properties": {
                            "mode": "Incremental",
                            "template": {
                                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                                "contentVersion": "1.0.0.0",
                                "parameters": {
                                    "resourceName": {
                                        "type": "string"
                                    },
                                    "logAnaltics": {
                                        "type": "string"
                                    },
                                    "location": {
                                        "type": "string"
                                    },
                                    "metricsEnabled": {
                                        "type": "string"
                                    },
                                    "logsEnabled": {
                                        "type": "string"
                                    },
                                    "profileName": {
                                        "type": "string"
                                    }
                                },
                                "variables": {},
                                "resources": [
                                    {
                                        "type": "Microsoft.Storage/storageAccounts/providers/diagnosticSettings",
                                        "apiVersion": "2017-05-01-preview",
                                        "name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', parameters('profileName'))]",
                                        "location": "[parameters('location')]",
                                        "dependsOn": [],
                                        "properties": {
                                            "workspaceId": "[parameters('logAnalytics')]",
                                            "metrics": [
                                                {
                                                    "category": "AllMetrics",
                                                    "enabled": true,
                                                    "retentionPolicy": {
                                                        "enabled": true,
                                                        "days": 365
                                                    }
                                                }
                                            ],
                                            "logs": [
                                                {
                                                    "category": "Audit",
                                                    "enabled": true
                                                },
                                                {
                                                    "category": "Requests",
                                                    "enabled": true
                                                }
                                            ]
                                        }
                                    }
                                ],
                                "outputs": {}
                            },
                            "parameters": {
                                "location": {
                                    "value": "[field('location')]"
                                },
                                "resourceName": {
                                    "value": "[field('name')]"
                                },
                                "profileName": {
                                    "value": "[parameters('profileName')]"
                                },
                                "metricsEnabled": {
                                    "value": "[parameters('metricsEnabled')]"
                                },
                                "logsEnabled": {
                                    "value": "[parameters('logsEnabled')]"
                                },
                                "logAnaltics": {
                                    "value": "[parameters('logAnalytics')]"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
4

1 回答 1

0

检查你的拼写错误,logAnaltics在你的 arm 模板中找到并恢复它们logAnalytics,让我知道它是否适合你。

尽管根据文档正确设置并引用了该参数,但它很可能是一个错字或类似的错误。

我已经找到了,可能还有更多。

于 2019-11-13T07:46:40.097 回答