Azure Resource Health Management Client Library for Python

1.0.0b6 · active · verified Thu Apr 16

The Azure Resource Health Management Client Library for Python enables developers to programmatically interact with Azure Resource Health, a service that provides information about the current and past health of Azure resources. It helps diagnose and get support for issues impacting resources, whether caused by Azure platform events or user actions. The current version is 1.0.0b6 and it's part of the broader Azure SDK for Python, which sees frequent updates across its various sub-packages.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then initialize `ResourceHealthMgmtClient` to list service health events across your subscription. Replace placeholder values like `YOUR_SUBSCRIPTION_ID` and potentially `resource_uri` with your actual Azure resource details. Ensure `AZURE_SUBSCRIPTION_ID` is set as an environment variable or passed explicitly.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcehealth import ResourceHealthMgmtClient

# Set your Azure Subscription ID as an environment variable, e.g., AZURE_SUBSCRIPTION_ID
# For local development, ensure you are logged in via Azure CLI (`az login`)
# or configure environment variables for service principal authentication.
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")

if subscription_id == "YOUR_SUBSCRIPTION_ID":
    raise ValueError("Please set the AZURE_SUBSCRIPTION_ID environment variable or replace the placeholder.")

# Authenticate using DefaultAzureCredential
# This credential provider chain will attempt various authentication methods.
credential = DefaultAzureCredential()

# Create the Resource Health Management Client
resource_health_client = ResourceHealthMgmtClient(
    credential=credential,
    subscription_id=subscription_id
)

# Example: List service health events in the subscription
print(f"Listing service health events for subscription ID: {subscription_id}")
for event in resource_health_client.events.list_by_subscription_id():
    print(f"  Event ID: {event.event_id}, Status: {event.impacted_resource_type}, Severity: {event.severity}, Status: {event.status}")

# Example: Get availability status for a specific resource (replace with your resource URI)
# resource_uri = "/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/{resource_provider}/{resource_type}/{resource_name}"
# print(f"\nGetting availability status for resource: {resource_uri}")
# try:
#     availability_status = resource_health_client.availability_statuses.get_by_resource(resource_uri=resource_uri)
#     print(f"  Availability State: {availability_status.availability_state}")
#     print(f"  Summary: {availability_status.summary}")
# except Exception as e:
#     print(f"  Could not retrieve availability status: {e}")

view raw JSON →