azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Get-AzDiagnosticSetting using old/limited API version

Open 1stewart opened this issue 4 years ago • 5 comments

Description

Using the latest version of Az.Monitor (3.0.0) installed by Az 7.2.1, the Get-AzDiagnosticSetting still uses the API version 2017-05-01-preview, that doesn't support retrieving diagnostic settings against LogAnalytics workspace resources. 2021-05-01-preview returns the expected result, as can be tested by querying that version directly, or at: https://docs.microsoft.com/en-us/rest/api/monitor/diagnostic-settings/get

Issue script & Debug output

PS C:\Users\{user}\Documents\Code\{repo}> Get-AzDiagnosticSetting -ResourceId /subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{resource} -Debug

DEBUG: 16:17:52 - GetAzureRmDiagnosticSettingCommand begin processing with ParameterSet 'ResourceIdParameterSet'.
DEBUG: 16:17:52 - using account id '{user}@{company}.com'...
WARNING: 16:17:52 - 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.
Confirm
Continue with this operation?
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Yes"): a
WARNING: 16:17:54 - 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: '{user}@{company}.com', environment: 'AzureCloud', tenant: '{tenant}'
DEBUG: 16:17:54 - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'{tenant}', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'{user}@{company}.com'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: 
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54] Found 1 cache accounts and 0 broker accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54] Returning 1 accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] MSAL MSAL.NetCore with assembly version '4.30.1.0'. CorrelationId(0bf8fbe2-32b5-4ae9-aae3-2605fa202955)
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] === AcquireTokenSilent Parameters ===
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] LoginHint provided: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Account provided: True
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] ForceRefresh: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - 0bf8fbe2-32b5-4ae9-aae3-2605fa202955

DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] === Token Acquisition (SilentRequest) started:

        Authority Host: login.microsoftonline.com
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Access token is not expired. Returning the found cache entry. [Current time (02/24/2022 16:17:54) - Expiration Time (02/24/2022 17:15:55 +00:00) - Extended Expiration Time (02/24/2022 17:15:55 +00:00)]
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Returning access token found in cache. RefreshOn exists ? False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Fetched access token from host login.microsoftonline.com.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] === Token Acquisition finished successfully. An access token was returned with Expiration Time: 02/24/2022 17:15:55 +00:00 and Scopes https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:  ExpiresOn: 2022-02-24T17:15:55.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '{tenant}', UserId: '{user}@{company}.com'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com//subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{resource}/providers/Microsoft.Insights/diagnosticSettings?api-version=2017-05-01-preview

Headers:
x-ms-client-request-id        : 8924d9a7-46ca-47a1-a5fc-6e164bc61f7f
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               : 53ec15a0-a5f7-488e-a0d1-98ccb1784ee6
Server                        : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-reads: 11992
x-ms-correlation-request-id   : 59265f67-cad2-40cf-ae98-d042a4e17363
x-ms-routing-request-id       : UKWEST:20220224T161751Z:59265f67-cad2-40cf-ae98-d042a4e17363
X-Content-Type-Options        : nosniff
Date                          : Thu, 24 Feb 2022 16:17:51 GMT

Body:
{
  "value": []
}


DEBUG: AzureQoSEvent: Module: Az.Monitor:3.0.0; CommandName: Get-AzDiagnosticSetting; PSVersion: 7.2.1; IsSuccess: True; Duration: 00:00:02.1151603
DEBUG: Finish sending metric.
DEBUG: 16:17:55 - GetAzureRmDiagnosticSettingCommand end processing.




(using the REST APIs directly)
GET https://management.azure.com//subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{resource}/providers/Microsoft.Insights/diagnosticSettings/test?api-version=2021-05-01-preview
Authorization: Bearer {token}

{
  "id": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/microsoft.operationalinsights/workspaces/{resource}/providers/microsoft.insights/diagnosticSettings/test",
  "type": "Microsoft.Insights/diagnosticSettings",
  "name": "test",
  "location": null,
  "kind": null,
  "tags": null,
  "properties": {
    "storageAccountId": null,
    "serviceBusRuleId": null,
    "workspaceId": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/microsoft.operationalinsights/workspaces/{resource}",
    "eventHubAuthorizationRuleId": null,
    "eventHubName": null,
    "metrics": [
      {
        "category": "AllMetrics",
        "enabled": false,
        "retentionPolicy": {
          "enabled": false,
          "days": 0
        }
      }
    ],
    "logs": [
      {
        "category": null,
        "categoryGroup": "audit",
        "enabled": true,
        "retentionPolicy": {
          "enabled": false,
          "days": 0
        }
      },
      {
        "category": null,
        "categoryGroup": "allLogs",
        "enabled": true,
        "retentionPolicy": {
          "enabled": false,
          "days": 0
        }
      }
    ],
    "logAnalyticsDestinationType": null
  },
  "identity": null
}

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
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.2                 Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount…}
Script     3.0.0                 Az.Monitor                          {Add-AzAutoscaleSetting, Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2…}

Error output

No error returned, older API returns a valid response by its schema (empty)

1stewart avatar Feb 24 '22 16:02 1stewart

+1

e-karlsson avatar Feb 25 '22 07:02 e-karlsson

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @AzmonLogA.

Issue Details

Description

Using the latest version of Az.Monitor (3.0.0) installed by Az 7.2.1, the Get-AzDiagnosticSetting still uses the API version 2017-05-01-preview, that doesn't support retrieving diagnostic settings against LogAnalytics workspace resources. 2021-05-01-preview returns the expected result, as can be tested by querying that version directly, or at: https://docs.microsoft.com/en-us/rest/api/monitor/diagnostic-settings/get

Issue script & Debug output

PS C:\Users\{user}\Documents\Code\{repo}> Get-AzDiagnosticSetting -ResourceId /subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{resource} -Debug

DEBUG: 16:17:52 - GetAzureRmDiagnosticSettingCommand begin processing with ParameterSet 'ResourceIdParameterSet'.
DEBUG: 16:17:52 - using account id '{user}@{company}.com'...
WARNING: 16:17:52 - 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.
Confirm
Continue with this operation?
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Yes"): a
WARNING: 16:17:54 - 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: '{user}@{company}.com', environment: 'AzureCloud', tenant: '{tenant}'
DEBUG: 16:17:54 - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'{tenant}', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'{user}@{company}.com'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: 
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54] Found 1 cache accounts and 0 broker accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54] Returning 1 accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] MSAL MSAL.NetCore with assembly version '4.30.1.0'. CorrelationId(0bf8fbe2-32b5-4ae9-aae3-2605fa202955)
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] === AcquireTokenSilent Parameters ===
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] LoginHint provided: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Account provided: True
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] ForceRefresh: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - 0bf8fbe2-32b5-4ae9-aae3-2605fa202955

DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] === Token Acquisition (SilentRequest) started:

        Authority Host: login.microsoftonline.com
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Access token is not expired. Returning the found cache entry. [Current time (02/24/2022 16:17:54) - Expiration Time (02/24/2022 17:15:55 +00:00) - Extended Expiration Time (02/24/2022 17:15:55 +00:00)]
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Returning access token found in cache. RefreshOn exists ? False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] Fetched access token from host login.microsoftonline.com.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19042 [02/24/2022 16:17:54 - ] === Token Acquisition finished successfully. An access token was returned with Expiration Time: 02/24/2022 17:15:55 +00:00 and Scopes https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:  ExpiresOn: 2022-02-24T17:15:55.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '{tenant}', UserId: '{user}@{company}.com'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com//subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{resource}/providers/Microsoft.Insights/diagnosticSettings?api-version=2017-05-01-preview

Headers:
x-ms-client-request-id        : 8924d9a7-46ca-47a1-a5fc-6e164bc61f7f
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               : 53ec15a0-a5f7-488e-a0d1-98ccb1784ee6
Server                        : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-reads: 11992
x-ms-correlation-request-id   : 59265f67-cad2-40cf-ae98-d042a4e17363
x-ms-routing-request-id       : UKWEST:20220224T161751Z:59265f67-cad2-40cf-ae98-d042a4e17363
X-Content-Type-Options        : nosniff
Date                          : Thu, 24 Feb 2022 16:17:51 GMT

Body:
{
  "value": []
}


DEBUG: AzureQoSEvent: Module: Az.Monitor:3.0.0; CommandName: Get-AzDiagnosticSetting; PSVersion: 7.2.1; IsSuccess: True; Duration: 00:00:02.1151603
DEBUG: Finish sending metric.
DEBUG: 16:17:55 - GetAzureRmDiagnosticSettingCommand end processing.




(using the REST APIs directly)
GET https://management.azure.com//subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{resource}/providers/Microsoft.Insights/diagnosticSettings/test?api-version=2021-05-01-preview
Authorization: Bearer {token}

{
  "id": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/microsoft.operationalinsights/workspaces/{resource}/providers/microsoft.insights/diagnosticSettings/test",
  "type": "Microsoft.Insights/diagnosticSettings",
  "name": "test",
  "location": null,
  "kind": null,
  "tags": null,
  "properties": {
    "storageAccountId": null,
    "serviceBusRuleId": null,
    "workspaceId": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/microsoft.operationalinsights/workspaces/{resource}",
    "eventHubAuthorizationRuleId": null,
    "eventHubName": null,
    "metrics": [
      {
        "category": "AllMetrics",
        "enabled": false,
        "retentionPolicy": {
          "enabled": false,
          "days": 0
        }
      }
    ],
    "logs": [
      {
        "category": null,
        "categoryGroup": "audit",
        "enabled": true,
        "retentionPolicy": {
          "enabled": false,
          "days": 0
        }
      },
      {
        "category": null,
        "categoryGroup": "allLogs",
        "enabled": true,
        "retentionPolicy": {
          "enabled": false,
          "days": 0
        }
      }
    ],
    "logAnalyticsDestinationType": null
  },
  "identity": null
}

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
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.2                 Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount…}
Script     3.0.0                 Az.Monitor                          {Add-AzAutoscaleSetting, Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2…}

Error output

No error returned, older API returns a valid response by its schema (empty)
Author: 1stewart
Assignees: -
Labels:

feature-request, Service Attention, Monitor - LogAnalytics, customer-reported

Milestone: -

ghost avatar Feb 25 '22 14:02 ghost

Thanks for reporting. We will evaluate effort and breaking change.

dingmeng-xue avatar Feb 25 '22 14:02 dingmeng-xue

@dingmeng-xue not sure why this is labelled as "feature-request", it is a bug if it doesn't return the right results.

This "categoryGroup": "allLogs", doesn't seem to be supported either? I can set a category, but i don't see a way using powershell to set a categoryGroup. [using az.monitor = 3.0.1]

sarah026 avatar Mar 21 '22 16:03 sarah026

Hi @1stewart @e-karlsson @sarah026 please try Az.Monitor-4.1.0-preview with this issue fixed: https://www.powershellgallery.com/packages/Az.Monitor/4.1.0-preview

VeryEarly avatar Aug 29 '22 07:08 VeryEarly