Subscription Diagnostic Settings for Azure Monitor
Description of the new feature
Need matching feature for Powershell that we have in CLI: https://github.com/Azure/azure-cli/issues/13692
Support Subscription Variant of Diagnostic Settings to export Activity Log, as documented at https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/preview/2017-05-01-preview/subscriptionDiagnosticsSettings_API.json
Proposed implementation details (optional)
This should look like Diagnostic Settings command (Set-AzDiagnosticSetting), but with Subscription as target, rather than resource ID. Note, retention setting is not supported. https://docs.microsoft.com/en-us/azure/azure-monitor/platform/diagnostic-settings This feature will eventually replace Add-AzLogProfile
Hi @nkiest ,
Az.Monitor depends on Dotnet management SDK generated from swagger specs, this feature was not included (SDK_Info) in the current SDK version 0.25.2-preview
We will plan this feature once SDK was ready.
Thanks
From @asheniam I was able to use the latest Azure Monitor SDK and list/create subscription diagnostic setting. https://www.nuget.org/packages/Microsoft.Azure.Management.Monitor/0.25.2-preview
Note: There isn't any 1st class SDK support for subscription diagnostic settings so from the SDK side, it looks like resource level diagnostic settings.
Example:
MonitorManagementClient client = new MonitorManagementClient(serviceCreds);
client.SubscriptionId = "c0b5f462-6f71-4a0e-9916-6250aae92ae1";
DiagnosticSettingsResourceCollection resource = client.DiagnosticSettings.List("/subscriptions/" + client.SubscriptionId);
client.DiagnosticSettings.CreateOrUpdate(
resourceUri: "/subscriptions/" + client.SubscriptionId,
parameters: resource.Value[1],
name: resource.Value[1].Name);
The PowerShell team should be unblocked.
Hi
Hi @nkiest ,
Az.Monitor depends on Dotnet management SDK generated from swagger specs, this feature was not included (SDK_Info) in the current SDK version 0.25.2-preview
We will plan this feature once SDK was ready.
Thanks
Hi, Please see the response above from nkiest and advise on the next steps. Thanks
From @asheniam I was able to use the latest Azure Monitor SDK and list/create subscription diagnostic setting. https://www.nuget.org/packages/Microsoft.Azure.Management.Monitor/0.25.2-preview
Note: There isn't any 1st class SDK support for subscription diagnostic settings so from the SDK side, it looks like resource level diagnostic settings.
Example:
MonitorManagementClient client = new MonitorManagementClient(serviceCreds); client.SubscriptionId = "c0b5f462-6f71-4a0e-9916-6250aae92ae1"; DiagnosticSettingsResourceCollection resource = client.DiagnosticSettings.List("/subscriptions/" + client.SubscriptionId); client.DiagnosticSettings.CreateOrUpdate( resourceUri: "/subscriptions/" + client.SubscriptionId, parameters: resource.Value[1], name: resource.Value[1].Name);The PowerShell team should be unblocked.
The SDK method referenced above "client.DiagnosticSettings.List" is from API: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/preview/2017-05-01-preview/diagnosticsSettings_API.json
which is different from: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/preview/2017-05-01-preview/subscriptionDiagnosticsSettings_API.json
Subscription level diagnostic setting cannot be created from Set-AzDiagnosticSetting is because API:
https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/preview/2017-05-01-preview/diagnosticsSettingsCategories_API.json
is not able to return the category for subscription.
Invoke-AzRestMethod -Path subscriptions/XXXXXXXXXXXX/providers/microsoft.insights/diagnosticSettingsCategories?api-version=2017-05-01-preview -Method GET
Headers : {[Cache-Control, System.String[]], [Pragma, System.String[]], [Strict-Transport-Security, System.String[]], [x-ms-request-id, System.String[]]…} Version : 1.1 StatusCode : 400 Method : GET Content : {"code":"BadRequest","message":""}
This preexisting API for activity log (was called event service, hence bad API name) provides a way to get valid categories for Subscription Diagnostic Settings: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/stable/2015-04-01/eventCategories_API.json
This preexisting API for activity log (was called event service, hence bad API name) provides a way to get valid categories for Subscription Diagnostic Settings: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/stable/2015-04-01/eventCategories_API.json
Hi @nkiest ,
I'll say it is possible to add some specific logic to handle subscription in powershell side:
-
get categories for subscription using event categories API
-
explicitly convert categories from above API to the type needed by https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/preview/2017-05-01-preview/diagnosticsSettings_API.json
However, it doesn't look appropriate to have this kind of logic in powershell side, ideal solution would be let API /{resourceUri}/providers/microsoft.insights/diagnosticSettingsCategories support subscription as resource.
Let me know if you have any concern.
@asheniam Any input on how categories gets returned? CLI team did some version of the first set of logic, so we thought we were good here.
this feature will be released with S185
you can set subscription diagnostic settings by: $list = @() Get-AzSubscriptionDiagnosticSettingCategory | ForEach-Object { $list += (New-AzDiagnosticDetailSetting -Log -Category $_.Name -Enabled) } $DiagnosticSettingName = 'please use your setting name here' $SubscriptionId = 'please use your subscription Id here' $WorkspaceId = 'please use your workspace Id here' $setting = New-AzDiagnosticSetting -Name $DiagnosticSettingName -SubscriptionId $SubscriptionId -WorkspaceId $WorkspaceId -Setting $list Set-AzDiagnosticSetting -InputObject $setting
In case anyone comes along and has trouble finding the cmdlet,
Get-AzSubscriptionDiagnosticSettingCategory replaced by Get-AzEventCategory
Az.Monitor Version 4.2.0 https://github.com/Azure/azure-powershell/blob/f67aaf4dbe62a9b9ed08bbb1fe885a1d39d4fce5/src/Monitor/Monitor/ChangeLog.md?plain=1#L115