在Azure中,您是否可以创建修改策略以启用登录存储帐户中的诊断设置?

时间:2019-11-13 02:40:45

标签: azure azure-policy

我创建了一个策略来补救没有启用诊断设置(经典)日志的存储帐户。但是我收到此错误:

{“代码”:“ DeploymentFailed”,“消息”:“至少一项资源部署操作失败。请列出部署操作以获取详细信息。请参阅https://aka.ms/arm-debug以获取使用详细信息。”,“详细信息”:[ {“ code”:“ BadRequest”,“ message”:“ {\ r \ n \” error \“:{\ r \ n \” code \“:\” InvalidTemplate \“,\ r \ n \” message \ “:\”无法在行'1'和列'429'处处理资源'/subscriptions/providers/Microsoft.Insights/diagnosticSettings/StorageLogs'的模板语言表达式。 '找不到模板参数'logAnalytics'。有关用法的详细信息,请参见https://aka.ms/arm-template/#parameters。'\“,\ r \ n \” additionalInfo \“:[\ r \ n {\ r \ n \” type \“:\” TemplateViolation \“,\ r \ n \“ info \”:{\ r \ n \“ lineNumber \”:1,\ r \ n \“ linePosition \”:429,\ r \ n \“ path \”:\“ \” \ r \ n } \ r \ n} \ r \ n] \ r \ n} \ 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')]"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

检查您的错字,在手臂模板中找到logAnaltics,然后将其恢复为logAnalytics,并告诉我它是否适合您。

该参数是根据文档正确设置的,并且也已被引用,因此很可能是拼写错误或此类错误。

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