Gallery › Network › Azure built-in policies
Configure diagnostic settings for Azure Network Security Groups to Log Analytics workspace
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Deploy diagnostic settings to Azure Network Security Groups to stream resource logs to a Log Analytics workspace.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONDataConnectorsAzureNSG_DINE.json · 167 lines
{
"properties": {
"displayName": "Configure diagnostic settings for Azure Network Security Groups to Log Analytics workspace",
"description": "Deploy diagnostic settings to Azure Network Security Groups to stream resource logs to a Log Analytics workspace.",
"policyType": "BuiltIn",
"mode": "Indexed",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"version": "1.0.0",
"parameters": {
"effect": {
"type": "string",
"defaultValue": "DeployIfNotExists",
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
},
"diagnosticsSettingNameToUse": {
"type": "String",
"metadata": {
"displayName": "Setting name",
"description": "Name of the policy for the diagnostics settings."
},
"defaultValue": "setByPolicy"
},
"logAnalytics": {
"type": "String",
"metadata": {
"displayName": "Log Analytics workspace",
"description": "Select the Log Analytics workspace from dropdown list",
"strongType": "omsWorkspace",
"assignPermissions": true
}
},
"NetworkSecurityGroupEventEnabled": {
"type": "String",
"metadata": {
"displayName": "NetworkSecurityGroupEvent - Enabled",
"description": "Whether to stream NetworkSecurityGroupEvent logs to the Log Analytics workspace - True or False"
},
"allowedValues": [
"True",
"False"
],
"defaultValue": "True"
},
"NetworkSecurityGroupRuleCounterEnabled": {
"type": "String",
"metadata": {
"displayName": "NetworkSecurityGroupRuleCounter - Enabled",
"description": "Whether to stream NetworkSecurityGroupRuleCounter logs to the Log Analytics workspace - True or False"
},
"allowedValues": [
"True",
"False"
],
"defaultValue": "True"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa",
"/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
],
"existenceCondition": {
"field": "Microsoft.Insights/diagnosticSettings/workspaceId",
"equals": "[parameters('logAnalytics')]"
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"diagnosticsSettingNameToUse": {
"type": "string"
},
"resourceName": {
"type": "string"
},
"logAnalytics": {
"type": "string"
},
"location": {
"type": "string"
},
"NetworkSecurityGroupEventEnabled": {
"type": "string"
},
"NetworkSecurityGroupRuleCounterEnabled": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups/providers/diagnosticSettings",
"apiVersion": "2017-05-01-preview",
"name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', parameters('diagnosticsSettingNameToUse'))]",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"workspaceId": "[parameters('logAnalytics')]",
"metrics": [],
"logs": [
{
"category": "NetworkSecurityGroupEvent",
"enabled": "[parameters('NetworkSecurityGroupEventEnabled')]"
},
{
"category": "NetworkSecurityGroupRuleCounter",
"enabled": "[parameters('NetworkSecurityGroupRuleCounterEnabled')]"
}
]
}
}
],
"outputs": {}
},
"parameters": {
"diagnosticsSettingNameToUse": {
"value": "[parameters('diagnosticsSettingNameToUse')]"
},
"logAnalytics": {
"value": "[parameters('logAnalytics')]"
},
"location": {
"value": "[field('location')]"
},
"resourceName": {
"value": "[field('name')]"
},
"NetworkSecurityGroupEventEnabled": {
"value": "[parameters('NetworkSecurityGroupEventEnabled')]"
},
"NetworkSecurityGroupRuleCounterEnabled": {
"value": "[parameters('NetworkSecurityGroupRuleCounterEnabled')]"
}
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/98a2e215-5382-489e-bd29-32e7190a39ba",
"name": "98a2e215-5382-489e-bd29-32e7190a39ba"
}Bylaw98a2e215-5382-489e-bd29-32e7190a39ba.bylaw.ps1 · 61 lines
# Converted from DataConnectorsAzureNSG_DINE.json by ConvertTo-Bylaw.
Policy '98a2e215-5382-489e-bd29-32e7190a39ba' {
Properties @{
DisplayName = 'Configure diagnostic settings for Azure Network Security Groups to Log Analytics workspace'
Description = 'Deploy diagnostic settings to Azure Network Security Groups to stream resource logs to a Log Analytics workspace.'
Version = '1.0.0'
Category = 'Network'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter Effect @{
Type = 'string'
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter DiagnosticsSettingNameToUse @{
Default = 'setByPolicy'
DisplayName = 'Setting name'
Description = 'Name of the policy for the diagnostics settings.'
}
Parameter LogAnalytics @{
Type = 'String'
DisplayName = 'Log Analytics workspace'
Description = 'Select the Log Analytics workspace from dropdown list'
Metadata = [ordered]@{ strongType = 'omsWorkspace'; assignPermissions = $true }
}
Parameter NetworkSecurityGroupEventEnabled @{
AllowedValues = @('True', 'False')
Default = 'True'
DisplayName = 'NetworkSecurityGroupEvent - Enabled'
Description = 'Whether to stream NetworkSecurityGroupEvent logs to the Log Analytics workspace - True or False'
JsonName = 'NetworkSecurityGroupEventEnabled'
}
Parameter NetworkSecurityGroupRuleCounterEnabled @{
AllowedValues = @('True', 'False')
Default = 'True'
DisplayName = 'NetworkSecurityGroupRuleCounter - Enabled'
Description = 'Whether to stream NetworkSecurityGroupRuleCounter logs to the Log Analytics workspace - True or False'
JsonName = 'NetworkSecurityGroupRuleCounterEnabled'
}
Resource 'Microsoft.Network/networkSecurityGroups'
DeployIfNotExists 'Microsoft.Insights/diagnosticSettings' -Role 'Monitoring Contributor', 'Log Analytics Contributor' -Effect (Param Effect) {
Require 'workspaceId is the LogAnalytics parameter' {
Field workspaceId | Must -Be (Param LogAnalytics)
}
Deployment -TemplateFile './templates/98a2e215-5382-489e-bd29-32e7190a39ba.json' -Parameters ([ordered]@{
diagnosticsSettingNameToUse = (Param DiagnosticsSettingNameToUse)
logAnalytics = (Param LogAnalytics)
location = (Arm '[field(''location'')]')
resourceName = (Arm '[field(''name'')]')
NetworkSecurityGroupEventEnabled = (Param NetworkSecurityGroupEventEnabled)
NetworkSecurityGroupRuleCounterEnabled = (Param NetworkSecurityGroupRuleCounterEnabled)
})
}
}Its deployment templates are written beside it:
templates/98a2e215-5382-489e-bd29-32e7190a39ba.json
Source: built-in-policies/policyDefinitions/Network/DataConnectorsAzureNSG_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw