Gallery › Storage › Azure Community Policy
Configure diagnostic settings for Table Services to Event Hub
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 4.0.1
Deploys the diagnostic settings for Table Services to stream resource logs to an Event Hub when any table Service which is missing this diagnostic settings is created or updated. The policy will set the diagnostic with Transaction metric and categories enabled. Made from the built-in policy for 'to Log Analytics workspace'. Note: This policy is not triggered upon Storage Account creation and requires creation of a remediation task in order to update for the account.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"name": "c5ab81f1-8edb-4fd2-be15-0e993f800f11",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Configure diagnostic settings for Table Services to Event Hub",
"description": "Deploys the diagnostic settings for Table Services to stream resource logs to an Event Hub when any table Service which is missing this diagnostic settings is created or updated. The policy will set the diagnostic with Transaction metric and categories enabled. Made from the built-in policy for 'to Log Analytics workspace'. Note: This policy is not triggered upon Storage Account creation and requires creation of a remediation task in order to update for the account.",
"metadata": {
"category": "Storage",
"version": "4.0.1"
},
"mode": "All",
"parameters": {
"profileName": {
"type": "String",
"metadata": {
"displayName": "Profile name",
"description": "The diagnostic settings profile name"
},
"defaultValue": "setbypolicy_tableServicesDiagnosticsLogsToEventHub"
},
"metricsEnabled": {
"type": "Boolean",
"metadata": {
"displayName": "Enable metrics",
"description": "Whether to enable metrics stream to the Event Hub - True or False"
},
"allowedValues": [
true,
false
],
"defaultValue": true
},
"logsEnabled": {
"type": "Boolean",
"metadata": {
"displayName": "Enable logs",
"description": "Whether to enable logs stream to the Event Hub - True or False"
},
"allowedValues": [
true,
false
],
"defaultValue": true
},
"eventHubRuleId": {
"type": "String",
"metadata": {
"displayName": "Event Hub Authorization Rule Id",
"description": "The Event Hub authorization rule Id for Azure Diagnostics. The authorization rule needs to be at Event Hub namespace level. e.g. /subscriptions/{subscription Id}/resourceGroups/{resource group}/providers/Microsoft.EventHub/namespaces/{Event Hub namespace}/authorizationrules/{authorization rule}",
"strongType": "Microsoft.EventHub/Namespaces/AuthorizationRules",
"assignPermissions": true
}
},
"eventHubName": {
"type": "String",
"metadata": {
"displayName": "Event Hub Name",
"description": "Specify the name of the Event Hub"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
},
"eventHubLocation": {
"type": "String",
"metadata": {
"displayName": "Event Hub Location",
"description": "Resource Location must be in the same location as the Event Hub Namespace.",
"strongType": "location"
},
"allowedValues": [
"swedencentral",
"westeurope"
],
"defaultValue": "westeurope"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts/tableServices"
},
{
"anyOf": [
{
"value": "[parameters('eventHubLocation')]",
"equals": ""
},
{
"field": "location",
"equals": "[parameters('eventHubLocation')]"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"name": "[parameters('profileName')]",
"existenceCondition": {
"allOf": [
{
"count": {
"field": "Microsoft.Insights/diagnosticSettings/metrics[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/metrics[*].category",
"equals": "Transaction"
},
{
"field": "Microsoft.Insights/diagnosticSettings/metrics[*].enabled",
"equals": "[parameters('metricsEnabled')]"
}
]
}
},
"equals": 1
},
{
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
"equals": "[parameters('logsEnabled')]"
},
{
"field": "Microsoft.Insights/diagnosticSettings/eventHubAuthorizationRuleId",
"matchInsensitively": "[parameters('eventHubRuleId')]"
},
{
"field": "Microsoft.Insights/diagnosticSettings/eventHubName",
"matchInsensitively": "[parameters('eventHubName')]"
}
]
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/f526a384-b230-433a-b45c-95f59c4a2dec",
"/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
],
"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"
},
"location": {
"type": "string"
},
"eventHubRuleId": {
"type": "string"
},
"metricsEnabled": {
"type": "bool"
},
"logsEnabled": {
"type": "bool"
},
"profileName": {
"type": "string"
},
"eventHubName": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts/tableServices/providers/diagnosticSettings",
"apiVersion": "2021-05-01-preview",
"name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', parameters('profileName'))]",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"eventHubAuthorizationRuleId": "[parameters('eventHubRuleId')]",
"eventHubName": "[parameters('eventHubName')]",
"metrics": [
{
"timeGrain": null,
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
},
"category": "Capacity"
},
{
"timeGrain": null,
"enabled": "[parameters('metricsEnabled')]",
"retentionPolicy": {
"days": 0,
"enabled": false
},
"category": "Transaction"
}
],
"logs": [
{
"category": "StorageRead",
"enabled": "[parameters('logsEnabled')]"
},
{
"category": "StorageWrite",
"enabled": "[parameters('logsEnabled')]"
},
{
"category": "StorageDelete",
"enabled": "[parameters('logsEnabled')]"
}
]
}
}
],
"outputs": {
"policy": {
"type": "string",
"value": "[concat('Diagnostic setting ', parameters('profileName'), ' for type Table Services (Microsoft.Storage/storageAccounts/tableServices), resourceName ', parameters('resourceName'), ' to EventHub ', parameters('eventHubRuleId'), ':', parameters('eventHubName'), ' configured')]"
}
}
},
"parameters": {
"location": {
"value": "[field('location')]"
},
"resourceName": {
"value": "[field('fullName')]"
},
"eventHubRuleId": {
"value": "[parameters('eventHubRuleId')]"
},
"metricsEnabled": {
"value": "[parameters('metricsEnabled')]"
},
"logsEnabled": {
"value": "[parameters('logsEnabled')]"
},
"profileName": {
"value": "[parameters('profileName')]"
},
"eventHubName": {
"value": "[parameters('eventHubName')]"
}
}
}
}
}
}
}
}
}# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'c5ab81f1-8edb-4fd2-be15-0e993f800f11' {
Properties @{
DisplayName = 'Configure diagnostic settings for Table Services to Event Hub'
Description = 'Deploys the diagnostic settings for Table Services to stream resource logs to an Event Hub when any table Service which is missing this diagnostic settings is created or updated. The policy will set the diagnostic with Transaction metric and categories enabled. Made from the built-in policy for ''to Log Analytics workspace''. Note: This policy is not triggered upon Storage Account creation and requires creation of a remediation task in order to update for the account.'
Category = 'Storage'
Version = '4.0.1'
Mode = 'All'
}
Parameter ProfileName @{
Default = 'setbypolicy_tableServicesDiagnosticsLogsToEventHub'
DisplayName = 'Profile name'
Description = 'The diagnostic settings profile name'
}
Parameter MetricsEnabled @{
Type = 'Boolean'
AllowedValues = @($true, $false)
Default = $true
DisplayName = 'Enable metrics'
Description = 'Whether to enable metrics stream to the Event Hub - True or False'
}
Parameter LogsEnabled @{
Type = 'Boolean'
AllowedValues = @($true, $false)
Default = $true
DisplayName = 'Enable logs'
Description = 'Whether to enable logs stream to the Event Hub - True or False'
}
Parameter EventHubRuleId @{
Type = 'String'
DisplayName = 'Event Hub Authorization Rule Id'
Description = 'The Event Hub authorization rule Id for Azure Diagnostics. The authorization rule needs to be at Event Hub namespace level. e.g. /subscriptions/{subscription Id}/resourceGroups/{resource group}/providers/Microsoft.EventHub/namespaces/{Event Hub namespace}/authorizationrules/{authorization rule}'
Metadata = [ordered]@{ strongType = 'Microsoft.EventHub/Namespaces/AuthorizationRules'; assignPermissions = $true }
}
Parameter EventHubName @{
Type = 'String'
DisplayName = 'Event Hub Name'
Description = 'Specify the name of the Event Hub'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter EventHubLocation @{
AllowedValues = @('swedencentral', 'westeurope')
Default = 'westeurope'
DisplayName = 'Event Hub Location'
Description = 'Resource Location must be in the same location as the Event Hub Namespace.'
Metadata = [ordered]@{ strongType = 'location' }
}
Resource 'Microsoft.Storage/storageAccounts/tableServices' {
Require 'Requirement 1' {
Param EventHubLocation | Must -Not -Be ''
}
Require 'location is not the EventHubLocation parameter' {
Field location | Must -Not -Be (Param EventHubLocation) -IfPresent
}
}
DeployIfNotExists 'Microsoft.Insights/diagnosticSettings' -Role 'Azure Event Hubs Data Owner', 'Log Analytics Contributor' -Name (Param ProfileName) -Effect (Param Effect) {
Require 'metrics, category, enabled and 3 more are as required' {
Count 'metrics[*]' -Where {
Field category | Must -Be 'Transaction'
Field enabled | Must -Be (Param MetricsEnabled)
} | Must -Be 1
Field logs.enabled | Must -Be (Param LogsEnabled)
Field eventHubAuthorizationRuleId | Must -Match (Param EventHubRuleId)
Field eventHubName | Must -Match (Param EventHubName)
}
Deployment -TemplateFile './templates/c5ab81f1-8edb-4fd2-be15-0e993f800f11.json' -Parameters ([ordered]@{
location = (Arm '[field(''location'')]')
resourceName = (Arm '[field(''fullName'')]')
eventHubRuleId = (Param EventHubRuleId)
metricsEnabled = (Param MetricsEnabled)
logsEnabled = (Param LogsEnabled)
profileName = (Param ProfileName)
eventHubName = (Param EventHubName)
})
}
}Its deployment templates are written beside it:
templates/c5ab81f1-8edb-4fd2-be15-0e993f800f11.json
Source: policyDefinitions/Monitoring/To Event Hub/Configure diagnostic settings for Table Services to Event Hub/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw