Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 5851a09

Browse files
Revised Event Hub Diagnostic Settings policy (Azure#339)
1 parent e5fe399 commit 5851a09

File tree

4 files changed

+228
-12
lines changed

4 files changed

+228
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "Deploy Diagnostic Settings for Event Hub to Log Analytics workspace",
3+
"mode": "indexed"
4+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"profileName": {
3+
"type": "String",
4+
"metadata": {
5+
"displayName": "Profile Name for Config",
6+
"description": "The profile name Azure Diagnostics"
7+
}
8+
},
9+
"logAnalytics": {
10+
"type": "string",
11+
"metadata": {
12+
"displayName": "logAnalytics",
13+
"description": "The target Log Analytics Workspace for Azure Diagnostics",
14+
"strongType": "omsWorkspace"
15+
}
16+
},
17+
"azureRegions": {
18+
"type": "Array",
19+
"metadata": {
20+
"displayName": "Allowed Locations",
21+
"description": "The list of locations that can be specified when deploying resources",
22+
"strongType": "location"
23+
}
24+
},
25+
"metricsEnabled": {
26+
"type": "String",
27+
"metadata": {
28+
"displayName": "Enable Metrics",
29+
"description": "Enable Metrics - True or False"
30+
},
31+
"allowedValues": [
32+
"True",
33+
"False"
34+
],
35+
"defaultValue": "False"
36+
},
37+
"logsEnabled": {
38+
"type": "String",
39+
"metadata": {
40+
"displayName": "Enable Logs",
41+
"description": "Enable Logs - True or False"
42+
},
43+
"allowedValues": [
44+
"True",
45+
"False"
46+
],
47+
"defaultValue": "True"
48+
}
49+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
2+
"if": {
3+
"allOf": [
4+
{
5+
"field": "type",
6+
"equals": "Microsoft.EventHub/namespaces"
7+
},
8+
{
9+
"field": "location",
10+
"in": "[parameters('AzureRegions')]"
11+
}
12+
]
13+
},
14+
"then": {
15+
"effect": "deployIfNotExists",
16+
"details": {
17+
"type": "Microsoft.Insights/diagnosticSettings",
18+
"existenceCondition": {
19+
"allOf": [
20+
{
21+
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
22+
"equals": "[parameters('LogsEnabled')]"
23+
},
24+
{
25+
"field": "Microsoft.Insights/diagnosticSettings/metrics.enabled",
26+
"equals": "[parameters('MetricsEnabled')]"
27+
},
28+
{
29+
"field": "Microsoft.Insights/diagnosticSettings/workspaceId",
30+
"equals": "[parameters('logAnalytics')]"
31+
}
32+
]
33+
},
34+
"roleDefinitionIds": [
35+
"/providers/Microsoft.Authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
36+
],
37+
"deployment": {
38+
"properties": {
39+
"mode": "incremental",
40+
"template": {
41+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
42+
"contentVersion": "1.0.0.0",
43+
"parameters": {
44+
"name": {
45+
"type": "string"
46+
},
47+
"location": {
48+
"type": "string"
49+
},
50+
"logAnalytics": {
51+
"type": "string"
52+
},
53+
"metricsEnabled": {
54+
"type": "string"
55+
},
56+
"logsEnabled": {
57+
"type": "string"
58+
},
59+
"profileName": {
60+
"type": "string"
61+
}
62+
},
63+
"variables": {},
64+
"resources": [
65+
{
66+
"type": "Microsoft.EventHub/namespaces/providers/diagnosticSettings",
67+
"apiVersion": "2017-05-01-preview",
68+
"name": "[concat(parameters('name'), '/', 'Microsoft.Insights/', parameters('profileName'))]",
69+
"location": "[parameters('location')]",
70+
"properties": {
71+
"workspaceId": "[parameters('logAnalytics')]",
72+
"metrics": [
73+
{
74+
"category": "AllMetrics",
75+
"enabled": "[parameters('metricsEnabled')]",
76+
"retentionPolicy": {
77+
"enabled": false,
78+
"days": 0
79+
}
80+
}
81+
],
82+
"logs": [
83+
{
84+
"category": "ArchiveLogs",
85+
"enabled": "[parameters('logsEnabled')]"
86+
},
87+
{
88+
"category": "OperationalLogs",
89+
"enabled": "[parameters('logsEnabled')]"
90+
},
91+
{
92+
"category": "AutoScaleLogs",
93+
"enabled": "[parameters('logsEnabled')]"
94+
},
95+
{
96+
"category": "KafkaCoordinatorLogs",
97+
"enabled": "[parameters('logsEnabled')]"
98+
},
99+
{
100+
"category": "KafkaUserErrorLogs",
101+
"enabled": "[parameters('logsEnabled')]"
102+
},
103+
{
104+
"category": "EventHubVNetConnectionEvent",
105+
"enabled": "[parameters('logsEnabled')]"
106+
},
107+
{
108+
"category": "CustomerManagedKeyUserLogs",
109+
"enabled": "[parameters('logsEnabled')]"
110+
},
111+
{
112+
"category": "RuntimeAuditLogs",
113+
"enabled": "[parameters('logsEnabled')]"
114+
},
115+
{
116+
"category": "ApplicationMetricsLogs",
117+
"enabled": "[parameters('logsEnabled')]"
118+
}
119+
]
120+
}
121+
}
122+
],
123+
"outputs": {
124+
"policy": {
125+
"type": "string",
126+
"value": "[concat(parameters('logAnalytics'), 'configured for diagnostic logs for ', ': ', parameters('name'))]"
127+
}
128+
}
129+
},
130+
"parameters": {
131+
"logAnalytics": {
132+
"value": "[parameters('logAnalytics')]"
133+
},
134+
"location": {
135+
"value": "[field('location')]"
136+
},
137+
"name": {
138+
"value": "[field('name')]"
139+
},
140+
"metricsEnabled": {
141+
"value": "[parameters('metricsEnabled')]"
142+
},
143+
"logsEnabled": {
144+
"value": "[parameters('logsEnabled')]"
145+
},
146+
"profileName": {
147+
"value": "[parameters('profileName')]"
148+
}
149+
}
150+
}
151+
}
152+
}
153+
}
154+
}

policy/custom/definitions/policyset/LogAnalytics.bicep

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,6 @@ resource policyset_name 'Microsoft.Authorization/policySetDefinitions@2020-03-01
223223
}
224224
}
225225
}
226-
{
227-
groupNames: [
228-
'BUILTIN'
229-
]
230-
policyDefinitionId: '/providers/Microsoft.Authorization/policyDefinitions/1f6e93e8-6b31-41b1-83f6-36e449a42579'
231-
policyDefinitionReferenceId: toLower(replace('Deploy Diagnostic Settings for Event Hub to Log Analytics workspace', ' ', '-'))
232-
parameters: {
233-
logAnalytics: {
234-
value: '[parameters(\'logAnalytics\')]'
235-
}
236-
}
237-
}
238226
{
239227
groupNames: [
240228
'BUILTIN'
@@ -1296,6 +1284,27 @@ resource policyset_name 'Microsoft.Authorization/policySetDefinitions@2020-03-01
12961284
}
12971285
}
12981286
}
1287+
{
1288+
groupNames: [
1289+
'CUSTOM'
1290+
]
1291+
policyDefinitionId: extensionResourceId(customPolicyDefinitionMgScope, 'Microsoft.Authorization/policyDefinitions', 'LA-Microsoft.EventHub-namespaces')
1292+
policyDefinitionReferenceId: toLower(replace('Deploy Diagnostic Settings for Event Hub to Log Analytics workspace', ' ', '-'))
1293+
parameters: {
1294+
logAnalytics: {
1295+
value: '[parameters(\'logAnalytics\')]'
1296+
}
1297+
profileName: {
1298+
value: 'setbypolicy_logAnalytics'
1299+
}
1300+
azureRegions: {
1301+
value: [
1302+
'canadacentral'
1303+
'canadaeast'
1304+
]
1305+
}
1306+
}
1307+
}
12991308
]
13001309
}
13011310
}

0 commit comments

Comments
 (0)