{"id":1373,"library":"azure-mgmt-monitor","title":"Azure Monitor Management Client Library","description":"The Microsoft Azure Monitor Client Library for Python allows you to manage Azure Monitor resources, including metric definitions, metrics, activity logs, diagnostic settings, and alerts. It's part of the Azure SDK for Python, which follows a predictable release cadence with frequent updates across its many client libraries.","status":"active","version":"7.0.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["Azure","Cloud","Monitoring","Management","Azure SDK"],"install":[{"cmd":"pip install azure-mgmt-monitor azure-identity","lang":"bash","label":"Install with authentication library"}],"dependencies":[{"reason":"Required for authentication with Azure services. It provides various credential types like DefaultAzureCredential.","package":"azure-identity","optional":false},{"reason":"Common base for all Azure management (track 2) client libraries.","package":"azure-mgmt-core","optional":false}],"imports":[{"symbol":"MonitorManagementClient","correct":"from azure.mgmt.monitor import MonitorManagementClient"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"},{"note":"Models are typically found in the 'models' submodule.","symbol":"MetricDefinition","correct":"from azure.mgmt.monitor.models import MetricDefinition"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.monitor import MonitorManagementClient\n\n# Set your Azure Subscription ID as an environment variable or replace 'YOUR_SUBSCRIPTION_ID'\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"YOUR_SUBSCRIPTION_ID\")\n\nif subscription_id == \"YOUR_SUBSCRIPTION_ID\":\n    print(\"WARNING: Please set the AZURE_SUBSCRIPTION_ID environment variable \")\n    print(\"         or replace 'YOUR_SUBSCRIPTION_ID' in the code.\")\n    # Attempt to proceed for demonstration, but subsequent calls will likely fail.\n\ntry:\n    # Authenticate using DefaultAzureCredential. This will try various methods\n    # (environment variables, managed identity, Azure CLI, VS Code, etc.)\n    credential = DefaultAzureCredential()\n\n    # Create a Monitor Management client\n    monitor_client = MonitorManagementClient(credential, subscription_id)\n\n    print(f\"Listing diagnostic settings categories for subscription '{subscription_id}'...\")\n    # The resource_uri can be a subscription, resource group, or specific resource.\n    # For listing categories, the subscription-level URI is sufficient.\n    resource_uri = f\"/subscriptions/{subscription_id}\"\n    categories = monitor_client.diagnostic_settings_categories.list(resource_uri=resource_uri)\n\n    found_categories = False\n    for category in categories:\n        print(f\"  - Category Name: {category.name}, Type: {category.category_type}\")\n        found_categories = True\n\n    if not found_categories:\n        print(\"No diagnostic settings categories found (or subscription ID/permissions are invalid).\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure you are authenticated (e.g., by running `az login`) \")\n    print(\"and that your AZURE_SUBSCRIPTION_ID environment variable is correctly set.\")\n","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then use `MonitorManagementClient` to list diagnostic settings categories available at the subscription level. This helps verify client instantiation and basic API interaction."},"warnings":[{"fix":"For versions <7.0.0, refer to the older documentation. For >=7.0.0, use `azure.identity` for authentication and note the client methods `begin_long_running_operation()` for async operations and direct iteration for paged lists. Most breaking changes were in the 1.x -> 2.x transition for `azure-mgmt-monitor` (and similar for other `azure-mgmt-*` libraries), with 7.0.0 being a stable Track 2 release.","message":"Major API changes from 'Track 1' (older) to 'Track 2' (current) versions. This includes different client constructors, model structures, and method signatures.","severity":"breaking","affected_versions":"<7.0.0"},{"fix":"Always use the `azure-identity` library. `DefaultAzureCredential` is recommended for local development and `ManagedIdentityCredential` or `ServicePrincipalCredential` (with environment variables) for production. Ensure you are logged in via `az login` for `AzureCliCredential` to work, or set up appropriate environment variables for other credential types.","message":"Authentication requires a credential object. Relying solely on older methods (e.g., hardcoded service principal credentials) is discouraged.","severity":"gotcha","affected_versions":"All"},{"fix":"Always construct or retrieve the full resource ID in the format `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}` for operations that target specific resources. The `resource_uri` parameter is common for this.","message":"Many Azure Monitor operations require full Azure Resource IDs (ARNs) rather than just resource names or GUIDs.","severity":"gotcha","affected_versions":"All"},{"fix":"Choose either the synchronous or asynchronous client (`MonitorManagementClient` or `MonitorManagementClientAsync`) at the beginning and stick to it. Asynchronous clients require an `async`/`await` context.","message":"Asynchronous clients are available for all management libraries, often denoted by an `Async` suffix (e.g., `MonitorManagementClientAsync`). Mixing synchronous and asynchronous code can lead to issues.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}