Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-AzPortalDashboard cmdlet does not work #17656

Open
cbellee opened this issue Mar 28, 2022 · 1 comment
Open

New-AzPortalDashboard cmdlet does not work #17656

cbellee opened this issue Mar 28, 2022 · 1 comment
Labels
bug good first issue Investigate 🔍 Portal

Comments

@cbellee
Copy link

@cbellee cbellee commented Mar 28, 2022

Description

New-AzPortalDashboard fails to parse a hashtable converted from a JSON dashboard definition downloaded from the portal.
The attached JSON dashboard definition was downloaded from an existing simple dashboard definition created in the portal in order to test creating a new dashboard definition using PowerShell. The commands and output are shown below.

portal.txt

Issue script & Debug output

PS C:\> $portal = Get-Content ./portal.json | Convertfrom-Json -AsHashtable
PS C:\> New-AzPortalDashboard -Lens $portal -ResourceGroupName dashboard-test-rg -Name dashboard-test-1 -Location australiaeast

DEBUG: [CmdletProcessRecordAsyncStart]: Created new QosEvent for command 'New-AzPortalDashboard_CreateExpanded'
DEBUG: CmdletProcessRecordAsyncStart: 
DEBUG: CmdletGetPipeline: 
DEBUG: CmdletBeforeAPICall: 
DEBUG: URLCreated: https://management.azure.com/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/dashboard-test-rg/providers/Microsoft.Portal/dashboards/dashboard-test-1?api-version=2019-01-01-preview
DEBUG: RequestCreated: https://management.azure.com/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/dashboard-test-rg/providers/Microsoft.Portal/dashboards/dashboard-test-1?api-version=2019-01-01-preview
DEBUG: HeaderParametersAdded: https://management.azure.com/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/dashboard-test-rg/providers/Microsoft.Portal/dashboards/dashboard-test-1?api-version=2019-01-01-preview
DEBUG: BodyContentSet: https://management.azure.com/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/dashboard-test-rg/providers/Microsoft.Portal/dashboards/dashboard-test-1?api-version=2019-01-01-preview
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/dashboard-test-rg/providers/Microsoft.Portal/dashboards/dashboard-test-1?api-version=2019-01-01-preview

Headers:

Body:
{
  "properties": {
    "lenses": {
      "properties": {
        "metadata": {
          "model": [
            "System.Collections.DictionaryEntry",
            "System.Collections.DictionaryEntry",
            "System.Collections.DictionaryEntry"
          ]
        },
        "order": 0
      }
    }
  },
  "location": "australiaeast"
}


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

Status Code:
BadRequest

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
X-Content-Type-Options        : nosniff
X-XSS-Protection              : 1; mode=block
x-ms-version                  : 9.333.0.1 (dev#c0d9102e47.220315-2159) Signed
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : production:7e506031-5eb6-43fd-9401-7f7f3380fd4e
X-UA-Compatible               : IE=edge
Set-Cookie                    : browserId=da829ab4-5afd-40d4-9f01-44044e1b873e; domain=portal.azure.com; path=/; secure; HttpOnly; SameSite=None
x-ms-ratelimit-remaining-subscription-writes: 1196
x-ms-correlation-request-id   : 3abd522a-5c3d-44d5-a876-1ff5f337cc70
x-ms-routing-request-id       : AUSTRALIAEAST:20220328T130639Z:3abd522a-5c3d-44d5-a876-1ff5f337cc70
Date                          : Mon, 28 Mar 2022 13:06:38 GMT

Body:
{
  "error": {
    "code": 37,
    "message": "The request content was invalid and could not be deserialized: 'Required property 'parts' not found in JSON. Path 'properties.lenses.properties', line 9, position 7.'."
  }
}


DEBUG: ResponseCreated: 
DEBUG: BeforeResponseDispatch: 
New-AzPortalDashboard_CreateExpanded: The request content was invalid and could not be deserialized: 'Required property 'parts' not found in JSON. Path 'properties.lenses.properties', line 9, position 7.'.
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSCloudException: InternalException' from response
DEBUG: Finally: 
DEBUG: CmdletAfterAPICall: 
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd: 
DEBUG: CmdletProcessRecordEnd: 
DEBUG: AzureQoSEvent: Module: Az.Portal:0.1.0; CommandName: New-AzPortalDashboard_CreateExpanded; PSVersion: 7.1.5; IsSuccess: False; Duration: 00:00:00; Exception: InternalException;
DEBUG: Finish sending metric.
DEBUG: CmdletEndProcessing:

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.5
PSEdition                      Core
GitCommitId                    7.1.5
OS                             Linux 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021
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.2                 Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAcco…
Script     0.1.0                 Az.Portal                           {Get-AzPortalDashboard, New-AzPortalDashboard, Remove-AzPortalDashbo…
Script     5.3.1                 Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment

Error output

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.

HistoryId: 1

Message        : The request content was invalid and could not be deserialized: 'Required property 'parts' not found in JSON. Path 'proper
                 ties.lenses.properties', line 6, position 7.'.
StackTrace     : 
Exception      : Microsoft.Azure.PowerShell.Cmdlets.Portal.Runtime.RestException`1[Microsoft.Azure.PowerShell.Cmdlets.Portal.Models.Api201
                 901Preview.IErrorResponse]
InvocationInfo : {New-AzPortalDashboard_CreateExpanded}
Line           : New-AzPortalDashboard -Lens $lens -ResourceGroupName dashboard-test-rg -Name dashboard-test-1 -Location australiaeast
Position       : At line:1 char:1
                 + New-AzPortalDashboard -Lens $lens -ResourceGroupName dashboard-test-r+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.
@cbellee cbellee added bug needs-triage labels Mar 28, 2022
@msftbot msftbot bot removed the needs-triage label Mar 28, 2022
@cbellee cbellee changed the title Update-AzPortalDashboard does not work New-AzPortalDashboard cmdlet does not work Mar 28, 2022
@dingmeng-xue dingmeng-xue added good first issue Portal Investigate 🔍 labels Mar 29, 2022
@ziyuezh576
Copy link
Contributor

@ziyuezh576 ziyuezh576 commented Jul 1, 2022

Hello. Your command is correct, but the content in your portal.txt is used for -DashboardPath parameter. The JSON, which would be converted to Hashtable, then to IDashboardPropertiesLenses automatically, should be like this. If succeed, you can see your dashboard at https://portal.azure.com/#@tenantId/dashboard/arm/subscriptions/subscriptionId/resourcegroups/dashboard-test-rg/providers/microsoft.portal/dashboards/dashboard-test-1

{
  "0": {
    "order": 0,
    "part": {
      "0": {
        "position": {
          "x": 0,
          "y": 0,
          "colSpan": 6,
          "rowSpan": 4
        },
        "metadata": {
          "inputs": [
            {
              "name": "options",
              "isOptional": true
            },
            {
              "name": "sharedTimeRange",
              "isOptional": true
            }
          ],
          "type": "Extension/HubsExtension/PartType/MonitorChartPart",
          "settings": {
            "content": {
              "options": {
                "chart": {
                  "metrics": [],
                  "title": "Metrics chart",
                  "titleKind": 1,
                  "visualization": {
                    "disablePinning": true
                  }
                }
              }
            }
          }
        }
      },
      "1": {
        "position": {
          "x": 6,
          "y": 0,
          "colSpan": 2,
          "rowSpan": 3
        },
        "metadata": {
          "inputs": [],
          "type": "Extension/Microsoft_Azure_Security/PartType/SecurityMetricGalleryTileViewModel"
        }
      }
    },
    "metadata": {
      "model": {
        "timeRange": {
          "value": {
            "relative": {
              "duration": 24,
              "timeUnit": 1
            }
          },
          "type": "MsPortalFx.Composition.Configuration.ValueTypes.TimeRange"
        },
        "filterLocale": {
          "value": "en-us"
        },
        "filters": {
          "value": {
            "MsPortalFx_TimeRange": {
              "model": {
                "format": "utc",
                "granularity": "auto",
                "relative": "24h"
              },
              "displayCache": {
                "name": "UTC Time",
                "value": "Past 24 hours"
              },
              "filteredPartIds": [
                "StartboardPart-MonitorChartPart-596f07a8-51dc-42d8-8316-9b03af964ba1"
              ]
            }
          }
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Investigate 🔍 Portal
Projects
None yet
Development

No branches or pull requests

3 participants