Skip to content

Commit b7bc248

Browse files
authored
Merge pull request #204434 from timwarner-msft/timwarner-eventadd
Refactor Event Grid integration details
2 parents 7a6ee51 + 3298df0 commit b7bc248

File tree

3 files changed

+169
-216
lines changed

3 files changed

+169
-216
lines changed

articles/event-grid/event-schema-policy.md

Lines changed: 5 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Azure Policy as an Event Grid source
3-
description: This article describes how to use Azure Policy as an Event Grid event source. It provides the schema and links to tutorial and how-to articles.
3+
description: This article describes how to use Azure Policy as an Event Grid event source. It provides the schema and links to tutorial and how-to articles.
44
ms.topic: conceptual
5-
author: DCtheGeek
6-
ms.author: dacoulte
7-
ms.date: 09/15/2021
5+
author: timwarner-msft
6+
ms.author: timwarner
7+
ms.date: 07/12/2022
88
---
99

1010
# Azure Policy as an Event Grid source
@@ -14,156 +14,7 @@ events. For an introduction to event schemas, see
1414
[Azure Event Grid event schema](./event-schema.md). It also gives you a list of quick starts and
1515
tutorials to use Azure Policy as an event source.
1616

17-
## Available event types
18-
19-
Azure Policy emits the following event types:
20-
21-
| Event type | Description |
22-
| ---------- | ----------- |
23-
| Microsoft.PolicyInsights.PolicyStateCreated | Raised when a policy compliance state is created. |
24-
| Microsoft.PolicyInsights.PolicyStateChanged | Raised when a policy compliance state is changed. |
25-
| Microsoft.PolicyInsights.PolicyStateDeleted | Raised when a policy compliance state is deleted. |
26-
27-
## Example event
28-
29-
# [Event Grid event schema](#tab/event-grid-event-schema)
30-
The following example shows the schema of a policy state created event:
31-
32-
```json
33-
[{
34-
"id": "5829794FCB5075FCF585476619577B5A5A30E52C84842CBD4E2AD73996714C4C",
35-
"topic": "/subscriptions/<SubscriptionID>",
36-
"subject": "/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>",
37-
"data": {
38-
"timestamp": "2021-03-27T18:37:42.4496956Z",
39-
"policyAssignmentId": "<policy-assignment-scope>/providers/microsoft.authorization/policyassignments/<policy-assignment-name>",
40-
"policyDefinitionId": "<policy-definition-scope>/providers/microsoft.authorization/policydefinitions/<policy-definition-name>",
41-
"policyDefinitionReferenceId": "",
42-
"complianceState": "NonCompliant",
43-
"subscriptionId": "<subscription-id>",
44-
"complianceReasonCode": ""
45-
},
46-
"eventType": "Microsoft.PolicyInsights.PolicyStateCreated",
47-
"eventTime": "2021-03-27T18:37:42.5241536Z",
48-
"dataVersion": "1",
49-
"metadataVersion": "1"
50-
}]
51-
```
52-
53-
The schema for a policy state changed event is similar:
54-
55-
```json
56-
[{
57-
"id": "5829794FCB5075FCF585476619577B5A5A30E52C84842CBD4E2AD73996714C4C",
58-
"topic": "/subscriptions/<SubscriptionID>",
59-
"subject": "/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>",
60-
"data": {
61-
"timestamp": "2021-03-27T18:37:42.4496956Z",
62-
"policyAssignmentId": "<policy-assignment-scope>/providers/microsoft.authorization/policyassignments/<policy-assignment-name>",
63-
"policyDefinitionId": "<policy-definition-scope>/providers/microsoft.authorization/policydefinitions/<policy-definition-name>",
64-
"policyDefinitionReferenceId": "",
65-
"complianceState": "NonCompliant",
66-
"subscriptionId": "<subscription-id>",
67-
"complianceReasonCode": ""
68-
},
69-
"eventType": "Microsoft.PolicyInsights.PolicyStateChanged",
70-
"eventTime": "2021-03-27T18:37:42.5241536Z",
71-
"dataVersion": "1",
72-
"metadataVersion": "1"
73-
}]
74-
```
75-
# [Cloud event schema](#tab/cloud-event-schema)
76-
77-
The following example shows the schema of a policy state created event:
78-
79-
```json
80-
[{
81-
"id": "5829794FCB5075FCF585476619577B5A5A30E52C84842CBD4E2AD73996714C4C",
82-
"source": "/subscriptions/<SubscriptionID>",
83-
"subject": "/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>",
84-
"data": {
85-
"timestamp": "2021-03-27T18:37:42.4496956Z",
86-
"policyAssignmentId": "<policy-assignment-scope>/providers/microsoft.authorization/policyassignments/<policy-assignment-name>",
87-
"policyDefinitionId": "<policy-definition-scope>/providers/microsoft.authorization/policydefinitions/<policy-definition-name>",
88-
"policyDefinitionReferenceId": "",
89-
"complianceState": "NonCompliant",
90-
"subscriptionId": "<subscription-id>",
91-
"complianceReasonCode": ""
92-
},
93-
"type": "Microsoft.PolicyInsights.PolicyStateCreated",
94-
"time": "2021-03-27T18:37:42.5241536Z",
95-
"specversion": "1.0"
96-
}]
97-
```
98-
99-
The schema for a policy state changed event is similar:
100-
101-
```json
102-
[{
103-
"id": "5829794FCB5075FCF585476619577B5A5A30E52C84842CBD4E2AD73996714C4C",
104-
"source": "/subscriptions/<SubscriptionID>",
105-
"subject": "/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>",
106-
"data": {
107-
"timestamp": "2021-03-27T18:37:42.4496956Z",
108-
"policyAssignmentId": "<policy-assignment-scope>/providers/microsoft.authorization/policyassignments/<policy-assignment-name>",
109-
"policyDefinitionId": "<policy-definition-scope>/providers/microsoft.authorization/policydefinitions/<policy-definition-name>",
110-
"policyDefinitionReferenceId": "",
111-
"complianceState": "NonCompliant",
112-
"subscriptionId": "<subscription-id>",
113-
"complianceReasonCode": ""
114-
},
115-
"type": "Microsoft.PolicyInsights.PolicyStateChanged",
116-
"time": "2021-03-27T18:37:42.5241536Z",
117-
"specversion": "1.0"
118-
}]
119-
```
120-
121-
---
122-
123-
## Event properties
124-
125-
# [Event Grid event schema](#tab/event-grid-event-schema)
126-
127-
An event has the following top-level data:
128-
129-
| Property | Type | Description |
130-
| -------- | ---- | ----------- |
131-
| `topic` | string | Full resource path to the event source. This field isn't writeable. Event Grid provides this value. |
132-
| `subject` | string | The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>` |
133-
| `eventType` | string | One of the registered event types for this event source. |
134-
| `eventTime` | string | The time the event is generated based on the provider's UTC time. |
135-
| `id` | string | Unique identifier for the event. |
136-
| `data` | object | Azure Policy event data. |
137-
| `dataVersion` | string | The schema version of the data object. The publisher defines the schema version. |
138-
| `metadataVersion` | string | The schema version of the event metadata. Event Grid defines the schema of the top-level properties. Event Grid provides this value. |
139-
140-
# [Cloud event schema](#tab/cloud-event-schema)
141-
142-
An event has the following top-level data:
143-
144-
| Property | Type | Description |
145-
| -------- | ---- | ----------- |
146-
| `source` | string | Full resource path to the event source. This field isn't writeable. Event Grid provides this value. |
147-
| `subject` | string | The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>` |
148-
| `type` | string | One of the registered event types for this event source. |
149-
| `time` | string | The time the event is generated based on the provider's UTC time. |
150-
| `id` | string | Unique identifier for the event. |
151-
| `data` | object | Azure Policy event data. |
152-
| `specversion` | string | CloudEvents schema specification version. |
153-
154-
---
155-
156-
The data object has the following properties:
157-
158-
| Property | Type | Description |
159-
| -------- | ---- | ----------- |
160-
| `timestamp` | string | The time (in UTC) that the resource was scanned by Azure Policy. For ordering events, use this property instead of the top-level `eventTime` or `time` properties. |
161-
| `policyAssignmentId` | string | The resource ID of the policy assignment. |
162-
| `policyDefinitionId` | string | The resource ID of the policy definition. |
163-
| `policyDefinitionReferenceId` | string | The reference ID for the policy definition inside the initiative definition, if the policy assignment is for an initiative. May be empty. |
164-
| `complianceState` | string | The compliance state of the resource with respect to the policy assignment. |
165-
| `subscriptionId` | string | The subscription ID of the resource. |
166-
| `complianceReasonCode` | string | The compliance reason code. May be empty. |
17+
[!INCLUDE [policy-events.md](../../includes/policy/policy-events.md)]
16718

16819
## Next steps
16920

articles/governance/policy/concepts/event-overview.md

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
22
title: Reacting to Azure Policy state change events
3-
description: Use Azure Event Grid to subscribe to App Policy events, which allow applications to react to state changes without the need for complicated code.
4-
ms.date: 08/17/2021
3+
description: Use Azure Event Grid to subscribe to Azure Policy events, which allow applications to react to state changes without the need for complicated code.
4+
ms.date: 07/12/2022
55
ms.topic: conceptual
6+
ms.author: timwarner
7+
author: timwarner-msft
68
---
79
# Reacting to Azure Policy state change events
810

@@ -32,66 +34,7 @@ for a full tutorial.
3234

3335
:::image type="content" source="../../../event-grid/media/overview/functional-model.png" alt-text="Event Grid model of sources and handlers" lightbox="../../../event-grid/media/overview/functional-model-big.png":::
3436

35-
## Available Azure Policy events
36-
37-
Event Grid uses [event subscriptions](../../../event-grid/concepts.md#event-subscriptions) to route
38-
event messages to subscribers. Azure Policy event subscriptions can include three types of events:
39-
40-
| Event type | Description |
41-
| ---------- | ----------- |
42-
| Microsoft.PolicyInsights.PolicyStateCreated | Raised when a policy compliance state is created. |
43-
| Microsoft.PolicyInsights.PolicyStateChanged | Raised when a policy compliance state is changed. |
44-
| Microsoft.PolicyInsights.PolicyStateDeleted | Raised when a policy compliance state is deleted. |
45-
46-
## Event schema
47-
48-
Azure Policy events contain all the information you need to respond to changes in your data. You can
49-
identify an Azure Policy event when the `eventType` property starts with "Microsoft.PolicyInsights".
50-
Additional information about the usage of Event Grid event properties is documented in
51-
[Event Grid event schema](../../../event-grid/event-schema.md).
52-
53-
| Property | Type | Description |
54-
| -------- | ---- | ----------- |
55-
| `id` | string | Unique identifier for the event. |
56-
| `topic` | string | Full resource path to the event source. This field isn't writeable. Event Grid provides this value. |
57-
| `subject` | string | The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>` |
58-
| `data` | object | Azure Policy event data. |
59-
| `data.timestamp` | string | The time (in UTC) that the resource was scanned by Azure Policy. For ordering events, use this property instead of the top level `eventTime` or `time` properties. |
60-
| `data.policyAssignmentId` | string | The resource ID of the policy assignment. |
61-
| `data.policyDefinitionId` | string | The resource ID of the policy definition. |
62-
| `data.policyDefinitionReferenceId` | string | The reference ID for the policy definition inside the initiative definition, if the policy assignment is for an initiative. May be empty. |
63-
| `data.complianceState` | string | The compliance state of the resource with respect to the policy assignment. |
64-
| `data.subscriptionId` | string | The subscription ID of the resource. |
65-
| `data.complianceReasonCode` | string | The compliance reason code. May be empty. |
66-
| `eventType` | string | One of the registered event types for this event source. |
67-
| `eventTime` | string | The time the event is generated based on the provider's UTC time. |
68-
| `dataVersion` | string | The schema version of the data object. The publisher defines the schema version. |
69-
| `metadataVersion` | string | The schema version of the event metadata. Event Grid defines the schema of the top-level properties. Event Grid provides this value. |
70-
71-
Here's an example of a policy state change event:
72-
73-
```json
74-
[{
75-
"id": "5829794FCB5075FCF585476619577B5A5A30E52C84842CBD4E2AD73996714C4C",
76-
"topic": "/subscriptions/<SubscriptionID>",
77-
"subject": "/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/providers/<ProviderNamespace>/<ResourceType>/<ResourceName>",
78-
"data": {
79-
"timestamp": "2021-03-27T18:37:42.4496956Z",
80-
"policyAssignmentId": "<policy-assignment-scope>/providers/microsoft.authorization/policyassignments/<policy-assignment-name>",
81-
"policyDefinitionId": "<policy-definition-scope>/providers/microsoft.authorization/policydefinitions/<policy-definition-name>",
82-
"policyDefinitionReferenceId": "",
83-
"complianceState": "NonCompliant",
84-
"subscriptionId": "<subscription-id>",
85-
"complianceReasonCode": ""
86-
},
87-
"eventType": "Microsoft.PolicyInsights.PolicyStateChanged",
88-
"eventTime": "2021-03-27T18:37:42.5241536Z",
89-
"dataVersion": "1",
90-
"metadataVersion": "1"
91-
}]
92-
```
93-
94-
For more information, see [Azure Policy events schema](../../../event-grid/event-schema-policy.md).
37+
[!INCLUDE [policy-events.md](../../../../includes/policy/policy-events.md)]
9538

9639
## Practices for consuming events
9740

0 commit comments

Comments
 (0)