0
0
Azurecloud~30 mins

Diagnostic settings for resources in Azure - Mini Project: Build & Apply

Choose your learning style9 modes available
Diagnostic settings for resources
📖 Scenario: You are managing an Azure environment and want to enable diagnostic settings on a resource to collect logs and metrics for monitoring and troubleshooting.
🎯 Goal: Create a diagnostic settings configuration for an Azure resource that sends logs and metrics to a storage account, an event hub, and a Log Analytics workspace.
📋 What You'll Learn
Create a dictionary called resource with the resource ID.
Create a dictionary called destinations with storage account ID, event hub authorization rule ID, and Log Analytics workspace ID.
Create a dictionary called diagnostic_settings with logs and metrics settings referencing the resource and destinations.
Add the final enabled flag set to true in the diagnostic settings.
💡 Why This Matters
🌍 Real World
Enabling diagnostic settings is essential for monitoring Azure resources, collecting logs and metrics for troubleshooting and compliance.
💼 Career
Cloud engineers and administrators often configure diagnostic settings to ensure visibility into resource health and activity.
Progress0 / 4 steps
1
Create the resource dictionary
Create a dictionary called resource with the key id set to the string "/subscriptions/12345/resourceGroups/myRG/providers/Microsoft.Compute/virtualMachines/myVM".
Azure
Need a hint?

Use a dictionary with key id and the exact resource ID string.

2
Create the destinations dictionary
Create a dictionary called destinations with keys storage_account_id, event_hub_authorization_rule_id, and workspace_id. Set their values to the strings "/subscriptions/12345/resourceGroups/myRG/providers/Microsoft.Storage/storageAccounts/mystorage", "/subscriptions/12345/resourceGroups/myRG/providers/Microsoft.EventHub/namespaces/myeventhub/authorizationRules/RootManageSharedAccessKey", and "/subscriptions/12345/resourceGroups/myRG/providers/Microsoft.OperationalInsights/workspaces/myworkspace" respectively.
Azure
Need a hint?

Use a dictionary with the exact keys and values for each destination.

3
Create the diagnostic settings dictionary
Create a dictionary called diagnostic_settings with keys resource_id, logs, metrics, storage_account_id, event_hub_authorization_rule_id, and workspace_id. Set resource_id to resource["id"]. Set logs to a list with one dictionary containing category as "Administrative" and enabled as true. Set metrics to a list with one dictionary containing category as "AllMetrics" and enabled as true. Set the destination IDs from the destinations dictionary accordingly.
Azure
Need a hint?

Use lists for logs and metrics with dictionaries inside. Reference resource["id"] and destinations values.

4
Enable the diagnostic settings
Add the key enabled with the value True to the diagnostic_settings dictionary to activate the diagnostic settings.
Azure
Need a hint?

Add the key enabled with value True inside the diagnostic_settings dictionary.