title | description | ms.topic | ms.custom | ms.date |
---|---|---|---|---|
Subscribe to Azure Resource Notifications - Health Resources events |
This article explains how to subscribe to events published by Azure Resource Notifications - Health Resources. |
how-to |
devx-track-azurecli, devx-track-azurepowershell |
09/08/2023 |
Subscribe to events raised by Azure Resource Notifications - Health Resources system topic (Preview)
This article explains the steps needed to subscribe to events published by Azure Resource Notifications - Health Resources. For detailed information about these events, see Azure Resource Notifications - Health Resources events.
-
Set the account to the Azure subscription where you wish to create the system topic.
az account set –s AZURESUBSCRIPTIONID
-
Create a system topic of type
microsoft.resourcenotifications.healthresources
using theaz eventgrid system-topic create
command.az eventgrid system-topic create --name SYSTEMTOPICNAME --resource-group RESOURCEGROUPNAME --source /subscriptions/AZURESUBSCRIPTIONID --topic-type microsoft.resourcenotifications.healthresources --location Global
-
Set the account to the Azure subscription where you wish to create the system topic.
Set-AzContext -Subscription AZURESUBSCRIPTIONID
-
Create a system topic of type
microsoft.resourcenotifications.healthresources
using the New-AzEventGridSystemTopic command.New-AzEventGridSystemTopic -name SYSTEMTOPICNAME -resourcegroup RESOURCEGROUPNAME -source /subscriptions/AZURESUBSCRIPTIONID -topictype microsoft.resourcenotifications.healthresources -location global
-
Sign into the Azure portal.
-
In the search bar, type Event Grid System Topics, and select it from the drop-down list.
-
On the Event Grid system topics page, select + Create on the toolbar.
-
On the Create Event Grid System Topic page, select Azure Resource Notifications - Health events for Topic type.
:::image type="content" source="./media/subscribe-to-resource-notifications-health-resources-events/create-topic.png" alt-text="Screenshot that shows the Create topic page in the Azure portal." lightbox="./media/subscribe-to-resource-notifications-health-resources-events/create-topic.png" :::
-
Select the resource group in which you want to create the system topic.
-
Enter a name for the system topic.
-
Select Review + create
:::image type="content" source="./media/subscribe-to-resource-notifications-health-resources-events/create-topic-full.png" alt-text="Screenshot that shows the full Create topic page with details in the Azure portal.":::
-
On the Review + create page, select Create.
-
On the successful deployment page, select Go to resource to navigate to the page for your system topic. You see the details about your system topic on this page.
:::image type="content" source="./media/subscribe-to-resource-notifications-health-resources-events/system-topic-home-page.png" alt-text="Screenshot that shows the System topic page in the Azure portal." lightbox="./media/subscribe-to-resource-notifications-health-resources-events/system-topic-home-page.png" :::
Create an event subscription for the above topic using the az eventgrid system-topic event-subscription create
command.
The following sample command creates an event subscription for the AvailabilityStatusChanged event.
az eventgrid system-topic event-subscription create --name EVENTSUBSCRIPTIONNAME --resource-group RESOURCEGROUPNAME --system-topic-name SYSTEMTOPICNAME –included-event-types Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged --endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/MYEVENTHUBSNAMESPACE/eventhubs/MYEVENTHUB --endpoint-type eventhub
The following sample command creates an event subscription for the ResourceAnnotated event.
az eventgrid system-topic event-subscription create --name EVENTSUBSCRIPTIONNAME --resource-group RESOURCEGROUPNAME --system-topic-name SYSTEMTOPICNAME –included-event-types Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated --endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/MYEVENTHUBSNAMESPACE/eventhubs/MYEVENTHUB --endpoint-type eventhub
If you don't specify included-event-types
, all the event types are included by default.
To filter events from a specific resource, use the --subject-begins-with
parameter. The example shows how to subscribe to AvailabilityStatusChanged
events for resources in a specified resource group.
az eventgrid system-topic event-subscription create --name EVENTSUBSCRIPTIONNAME --resource-group RESOURCEGROUPNAME --system-topic-name SYSTEMTOPICNAME –included-event-types Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged --endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/MYEVENTHUBSNAMESPACE/eventhubs/MYEVENTHUB --endpoint-type eventhub --subject-begins-with /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/SOURCERESOURCEGROUP/
Create an event subscription for the above topic using the New-AzEventGridSystemTopicEventSubscription command.
The following sample command creates an event subscription for the AvailabilityStatusChanged event.
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName EVENTSUBSCRIPTIONNAME -ResourceGroupName RESOURCEGROUPNAME -SystemtopicName SYSTEMTOPICNAME -IncludedEventType Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged -Endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/EVENTHUBSNAMESPACE/eventhubs/EVENTHUB -EndpointType eventhub
The following sample command creates an event subscription for the ResourceAnnotated event.
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName EVENTSUBSCRIPTIONNAME -ResourceGroupName RESOURCEGROUPNAME -SystemtopicName SYSTEMTOPICNAME -IncludedEventType Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated -Endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/EVENTHUBSNAMESPACE/eventhubs/EVENTHUB -EndpointType eventhub
If you don't specify IncludedEventType
, all the event types are included by default.
To filter events from a specific resource, use the -SubjectBeginsWith
parameter. The example shows how to subscribe to AvailabilityStatusChanged
events from resources in a specified resource group.
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName EVENTSUBSCRIPTIONNAME -ResourceGroupName RESOURCEGROUPNAME -SystemtopicName SYSTEMTOPICNAME -IncludedEventType Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged -Endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/EVENTHUBSNAMESPACE/eventhubs/EVENTHUB -EndpointType eventhub -SubjectBeginsWith /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/SOURCERESOURCEGROUP/
-
On the Event Grid System Topic page, select + Event Subscription on the toolbar.
-
Confirm that the Topic Type, Source Resource, and Topic Name are automatically populated.
-
Enter a name for the event subscription.
-
For Filter to event types, select the event, for example, Availability status changed or Resource annotated.
:::image type="content" source="./media/subscribe-to-resource-notifications-health-resources-events/create-event-subscription-select-event.png" alt-text="Screenshot that shows the Create Event Subscription page." lightbox="./media/subscribe-to-resource-notifications-health-resources-events/create-event-subscription-select-event.png":::
-
Select endpoint type.
-
Configure event handler based no the endpoint type you selected. In the following example, an Azure event hub is selected.
:::image type="content" source="./media/subscribe-to-resource-notifications-health-resources-events/select-endpoint.png" alt-text="Screenshot that shows the Create Event Subscription page with an event handler." lightbox="./media/subscribe-to-resource-notifications-health-resources-events/select-endpoint.png":::
-
Select the Filters tab to provide subject filtering and advanced filtering. For example, to filter for events from resources in a specific resource group, follow these steps:
-
Select Enable subject filtering.
-
In the Subject Filters section, for Subject begins with, provide the value of the resource group in this format:
/subscriptions/{subscription-id}/resourceGroups/{resourceGroup-id}
.:::image type="content" source="./media/subscribe-to-resource-notifications-health-resources-events/filter.png" alt-text="Screenshot that shows the Filters tab of the Create Event Subscription page." lightbox="./media/subscribe-to-resource-notifications-health-resources-events/filter.png":::
-
-
Then, select Create to create the event subscription.
To delete the event subscription, use the az eventgrid system-topic event-subscription delete
command. Here's an example:
az eventgrid system-topic event-subscription delete --name firstEventSubscription --resourcegroup sampletestrg --system-topic-name arnSystemTopicHealth
To delete the system topic, use the az eventgrid system-topic delete
command. Here's an example:
az eventgrid system-topic delete --name arnsystemtopicHealth --resource-group sampletestrg
To delete an event subscription, use the Remove-AzEventGridSystemTopicEventSubscription
command. Here's an example:
Remove-AzEventGridSystemTopicEventSubscription -EventSubscriptionName firstEventSubscription -ResourceGroupName sampletestrg -SystemTopicName arnSystemTopicHealth
To delete the system topic, use the Remove-AzEventGridSystemTopic
command. Here's an example:
Remove-AzEventGridSystemTopic -ResourceGroupName sampletestrg -Name arnsystemtopicHealth
- Sign in to the Azure portal.
- In the search bar, type Event Grid System Topics, and press ENTER.
- Select the system topic.
- On the Event Grid System Topic page, select Delete on the toolbar.
You might want to filter to events that require an action. Near real-time alerts are critical in enabling quick mitigation actions. By filtering to Azure initiated and unplanned activity, you can become instantly aware of unanticipated activity across the workloads that requires immediate attention. You might want to redeploy or trigger communication to your end-users to notify the impact.
az eventgrid system-topic event-subscription create \
--name firstEventSubscription \
--resource-group sampletestrg \
--system-topic-name arnSystemTopicHealth
--included-event-types Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated \
--endpoint /subscriptions/000000000-0000-0000-0000-000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources \
--endpoint-type evenhub \
--advanced-filter data.resourceInfo.properties.context StringEndsWith Platform Initiated \
--advanced-filter data.resourceInfo.properties.category StringEndsWith Unplanned
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName firstEventSubscription -ResourceGroupName sampletestrg -SystemtopicName arnSystemTopicHealth -IncludedEventType Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated -Endpoint /subscriptions/000000000-0000-0000-0000-000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources -EndpointType eventhub -AdvancedFilter @(@{operator = "StringEndsWith"; key = "data.resourceInfo.properties.context" ; value ="Platform Initiated"}, @{operator = "StringEndsWith"; key = "data.resourceInfo.properties.category" ; value ="Unplanned"})
-
Choose Resource Annotated as the event type.
-
In the Filters tab of the event subscription, choose the following advanced filters.
- Key = data.resourceInfo.properties.context - Operator = StringEndsWith - Value = Platform Initiated AND - Key = data.resourceInfo.properties.category - Operator = StringEndsWith - Value = Unplanned
Having the ability to filter to the resource types that require attention or mitigation upon impact can enable you to focus on what matters. Even within VMs, perhaps you only care when health of the parent or entire virtual machine scale set is affected versus when an instance in a virtual machine scale set is affected. This filter allows you to precisely hone in on the type of resources for which you want the near real-time alerts.
az eventgrid system-topic event-subscription create \
--name firstEventSubscription \
--resource-group sampletestrg \
--system-topic-name arnSystemTopicHealth \
--included-event-types Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated \
--endpoint/subscriptions/000000000-0000-0000-0000-0000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources \
--endpoint-type evenhub \
--advanced-filter data.resourceInfo.targetResourceType StringContains Microsoft.Compute/virtualMachines
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName firstEventSubscription -ResourceGroupName sampletestrg -SystemtopicName arnSystemTopicHealth -IncludedEventType Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated -Endpoint /subscriptions/000000000-0000-0000-0000-000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources -EndpointType eventhub -AdvancedFilter @(@{operator = "StringContains"; key = "data.resourceInfo.properties.targetResourceType" ; value ="Microsoft.Compute/virtualMachines"})
In the Filters tab of the event subscription, choose the following advanced filters.
Key = data.resourceInfo.properties.targetResourceType
Operator = String contains
Value = Microsoft.Compute/virtualMachines
[!INCLUDE contact-resource-notifications]
For detailed information about these events, see Azure Resource Notifications - Health Resources events.