Redaguoti

Bendrinti naudojant


Subscribe to Health Resources events and send them to Azure monitor alerts (Preview)

Health Resources system topic in Azure Event Grid provides accurate, reliable, and comprehensive information on health of your Azure resources such as single instance virtual machines (VMs), Virtual Machine Scale Set VMS, and Virtual Machine Scale Sets. This feature enables a deeper understanding of the diverse service issues impacting your resources. You can now set up Azure Monitor alerts to notify you when your workload is impacted.

Prerequisites

Create and configure the event subscription

  1. Navigate to the Event Grid system topic you created as part of the prerequisites.

  2. Select + Event Subscription on the command bar.

    Screenshot that shows the System Topic page with Create Subscription button selected.

  3. Enter a name for event subscription.

  4. For Event Schema, select the event schema as Cloud Events Schema v1.0. It's the only schema type that the Azure Monitor alerts destination supports.

  5. Select the Topic Type to microsoft resourcenotifications healthresources.

  6. For Event Types, select the event types that you're interested in. In this case, select the two event types offered for consumption: AvailabilityStatusChanged and ResourceAnnotated.

  7. For Endpoint Type, select Azure Monitor Alert as a destination.

  8. Select Configure an endpoint link.

  9. On the Select Monitor Alert Configuration page, follow these steps.

    1. Select the alert severity.
    2. [Optional] Select the action group. See Create an action group in the Azure portal.
    3. Enter a description for the alert.
    4. Select Confirm Selection.
  10. Now, on the Create Event Subscription page, select Create to create the event subscription. For detailed steps, see subscribe to events through portal.

    Screenshot that shows the Create Event Subscription page.

Azure Monitor alerts

In Azure monitor alerts, the Event Grid alerts appear as shown in the following image.

Sample Event Grid alert for AvailabilityStatusChanged:

Screenshot that shows the sample Availability Status Changed alert in Azure Monitor.

Sample Event Grid alert for ResourceAnnotated:

Screenshot that shows the sample Resource Annotated alert in Azure Monitor.

Event Filters

The event filter enables users to receive alerts for a specific resource group, specific transitions (when the availability state changes), or specific annotations (see Resource Health virtual machine Health Annotations for the full list of annotations). Users can use this feature to customize their alerts based on their specific monitoring needs.

  1. 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:

    1. Select Enable subject filtering.

    2. 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}.

      Screenshot that shows the filters in the event subscription.

    3. Alternately, filter for a specific resource by specifying the resource name in the Subject ends with parameter within the advanced filters introduced in the next step.

  2. For advanced filtering, navigate to the Filters tab of the event subscription and select Advanced filters. For detailed instructions, see Event filtering for Azure Event Grid.

    For example, to get alerted when VMs go down, set a filter to look for VM availability transitions that go from Available to Unavailable. It's done by creating the following conditions:

    • Available is in the key data.resourceInfo.properties.availabilityState and

    • Unavailable is in data.resourceInfo.properties.availabilityState

      Screenshot that shows the advanced filters in the event subscription.

Sample JSON events

Sample ResourceAnnotated event

Here's a sample ResourceAnnotated event. Notice that the type is set to Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated.

{
    "id": "sample-id",
    "source": "/subscriptions/sample-subscription",
    "specversion": "1.0",
    "type": "Microsoft.ResourceNotifications.HealthResources.ResourceAnnotated",
    "subject": "/subscriptions/sample-subscription/resourceGroups/sample-rg/providers/Microsoft.Compute/virtualMachines/sample-machine",
    "time": "2024-02-22T01:39:48.3385828Z",
    "data": {
        "resourceInfo": {
            "id": "/subscriptions/sample-subscription/resourceGroups/sample-rg/providers/Microsoft.Compute/virtualMachines/sample-machine/providers/Microsoft.ResourceHealth/resourceAnnotations/current",
            "name": "current",
            "type": "Microsoft.ResourceHealth/resourceAnnotations",
            "properties": {
                "targetResourceId": "/subscriptions/sample-subscription/resourceGroups/sample-rg/providers/Microsoft.Compute/virtualMachines/sample-machine",
                "targetResourceType": "Microsoft.Compute/virtualMachines",
                "occurredTime": "2024-02-22T01:39:48.3385828Z",
                "annotationName": "VirtualMachineRebootInitiatedByControlPlane",
                "reason": "Rebooted by user",
                "summary": "The Virtual Machine is undergoing a reboot as requested by an authorized user or process from within the Virtual machine. No other action is required at this time. ",
                "context": "Customer Initiated",
                "category": "Not Applicable",
                "impactType": "Informational"
            }
        },
        "operationalInfo": {
            "resourceEventTime": "2024-02-22T01:39:48.3385828+00:00"
        },
        "apiVersion": "2022-08-01"
    }
}

Sample AvailabilityStatusChanged event

Here's a sample AvailabilityStatusChanged event. Notice that the type is set to Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged.

{
    "id": "sample-id",
    "source": "/subscriptions/sample-subscription",
    "specversion": "1.0",
    "type": "Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged",
    "subject": "/subscriptions/sample-subscription/resourceGroups/sample-rg/providers/Microsoft.Compute/virtualMachines/sample-machine",
    "time": "2024-02-22T01:40:17.6532683Z",
    "data": {
        "resourceInfo": {
            "id": "/subscriptions/sample-subscription/resourceGroups/sample-rg/providers/Microsoft.Compute/virtualMachines/sample-machinee/providers/Microsoft.ResourceHealth/availabilityStatuses/current",
            "name": "current",
            "type": "Microsoft.ResourceHealth/availabilityStatuses",
            "properties": {
                "targetResourceId": "/subscriptions/sample-subscription/resourceGroups/sample-rg/providers/Microsoft.Compute/virtualMachines/sample-machine",
                "targetResourceType": "Microsoft.Compute/virtualMachines",
                "occurredTime": "2024-02-22T01:39:50.177Z",
                "previousAvailabilityState": "Available",
                "availabilityState": "Unavailable"
            }
        },
        "operationalInfo": {
            "resourceEventTime": "2024-02-22T01:39:50.177+00:00"
        },
        "apiVersion": "2023-12-01"
    }
}

Next steps

See the following articles: