Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Get-AzDiagnosticSetting does not retrieve Diagnostic settings of a key Vault #17990

Open philenko opened 2 years ago

philenko commented 2 years ago

Description

Get-AzDiagnosticSetting is not able to retrieve existing diagnostics settings of a key vault .

I have 5 key vaults, all diagnostic logging configures to log audit and metrics to a log analytics workspace. Cannot retrieve any diagnostics settings using Get-AzDiagnosticSetting and ResourceId

The expected outcome is to be able to retrieve the existing settings .

Issue script & Debug output

# Create a key vault ; assume name is myloggingkeyvault001
# set up diagnostic settings ; all settings are logging into a log analytics workspace 
PS /home/daka> $vaultName = "myloggingkeyvault001"     
PS /home/daka> $vault = Get-AzKeyVault -Name $vaultName
# private debug info removed 
PS /home/daka> $diag = Get-AzDiagnosticSetting -ResourceId $vault.ResourceId
DEBUG: 9:49:19 PM - GetAzureRmDiagnosticSettingCommand begin processing with ParameterSet 'ResourceIdParameterSet'.
DEBUG: 9:49:19 PM - using account id 'MSI@50342'...
WARNING: 9:49:19 PM - *** The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.
WARNING: 9:49:19 PM - *** The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.
DEBUG: [Common.Authentication]: Authenticating using Account: 'MSI@50342', environment: 'AzureCloud', tenant: 'redacted'
DEBUG: 9:49:19 PM - [ManagedServiceIdentityAuthenticator] Calling ManagedIdentityCredential.GetTokenAsync - TenantId:'redacted', Scopes:'https://management.core.windows.net/', UserId:''
DEBUG: ManagedIdentityCredential.GetToken invoked. Scopes: [ https://management.core.windows.net/ ] ParentRequestId: 
DEBUG: Request [19340e3f-0421-476a-bbeb-0758cc8ff9f4] POST http://localhost:50342/oauth2/token
Metadata:REDACTED
x-ms-client-request-id:19340e3f-0421-476a-bbeb-0758cc8ff9f4
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.5.0,(.NET 6.0.3; Linux 5.4.0-1077-azure #80~18.04.1-Ubuntu SMP Wed Apr 13 02:07:09 UTC 2022)
Content-Type:application/x-www-form-urlencoded
client assembly: Azure.Identity
DEBUG: Response [19340e3f-0421-476a-bbeb-0758cc8ff9f4] 200 OK (00.0s)
X-Powered-By:REDACTED
ETag:W/"8be-vLE3eLfvp1XZFKLbDNvoyoV4G7E"
Date:Tue, 26 Apr 2022 21:49:19 GMT
Connection:keep-alive
Content-Type:application/json; charset=utf-8
Content-Length:2238

DEBUG: ManagedIdentityCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net/ ] ParentRequestId:  ExpiresOn: 2022-04-26T22:26:38.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: 'redacted', UserId: 'MSI@50342'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com//subscriptions/redacted/resourceGroups/redacted/providers/Microsoft.KeyVault/vaults/redactred/providers/Microsoft.Insights/diagnosticSettings?api-version=2017-05-01-preview

Headers:
x-ms-client-request-id        : ce42e225-efcf-4354-9fdf-8b3a0c3c8209
Accept-Language               : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : ae9ea9e7-f2b9-4d30-905d-d63720cfe931
Server                        : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-reads: 11997
x-ms-correlation-request-id   : 877e7bb5-95d8-4ac4-a92f-065e7f9ff2db
x-ms-routing-request-id       : WESTUS:20220426T214921Z:877e7bb5-95d8-4ac4-a92f-065e7f9ff2db
X-Content-Type-Options        : nosniff
Date                          : Tue, 26 Apr 2022 21:49:20 GMT

Body:
{
  "value": []
}

DEBUG: AzureQoSEvent: Module: Az.Monitor:3.0.1; CommandName: Get-AzDiagnosticSetting; PSVersion: 7.2.2; IsSuccess: True; Duration: 00:00:01.6113254
DEBUG: Finish sending metric.
DEBUG: 9:49:21 PM - GetAzureRmDiagnosticSettingCommand end processing.
PS /home/daka> $diag 
PS /home/daka>

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.2
PSEdition                      Core
GitCommitId                    7.2.2
OS                             Linux 5.4.0-1077-azure #80~18.04.1-Ubuntu SMP Wed Apr 13 02:07:09 UTC 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.7.6                 Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount…}
Script     4.26.0                Az.Compute                          {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendContent, Add-AzVMDataDisk…}
Script     4.4.0                 Az.KeyVault                         {Add-AzKeyVaultCertificate, Add-AzKeyVaultCertificateContact, Add-AzKeyVaultKey, Add-AzKeyVaultManagedStorageAccount…}
Script     3.0.1                 Az.Monitor                          {Add-AzAutoscaleSetting, Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2…}
Script     4.16.1                Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplicationGatewayBackendAddressPool, Add-AzApplicationGatewayBackendHttpSetting, Add-AzApplicationGatewayCustomError…}
Script     5.6.0                 Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}
Script     4.5.0                 Az.Storage                          {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccountNetworkRule, Close-AzStorageFileHandle…}
Script     0.0.0.10              AzureAD.Standard.Preview            {Add-AzureADApplicationOwner, Add-AzureADDeviceRegisteredOwner, Add-AzureADDeviceRegisteredUser, Add-AzureADDirectoryRoleMember…}
Script     0.9.3                 AzurePSDrive

Error output

PS /home/daka> Resolve-AzError
DEBUG: 9:54:49 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 9:54:49 PM - using account id 'MSI@50342'...
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.

DEBUG: AzureQoSEvent: Module: Az.Accounts:2.7.6; CommandName: Resolve-AzError; PSVersion: 7.2.2; IsSuccess: True; Duration: 00:00:00.0040134
DEBUG: Finish sending metric.
DEBUG: 9:54:50 PM - ResolveError end processing.
dingmeng-xue commented 2 years ago

Thanks for reporting. We are looking into it.

purushotham-daimler commented 2 years ago

@dingmeng-xue any updates? We heavily depend on this..

danielfears commented 10 months ago

Bumping this - required also.