Skip to content

az monitor scheduled-query list is throwing Cannot deserialize as [Action] error #18543

Closed
Azure/azure-cli-extensions
#3526

Description

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug
When we will run command from GitHub Actions az monitor scheduled-query list --debug --subscription ${{ env.SUBSCRIPTION}} -g ${{ env.RESOURCEGROUP }} it will randomally fail because of error message:
msrest.exceptions.DeserializationError: Cannot deserialize as [Action] an object of type <class 'dict'>

To Reproduce
You can run this command via GitHub Actions from GitHub runner ubuntu-latest and it will randomly happened.

Expected behavior
It will list all query alerts from specified subscription and resource group

Environment summary
It's GitHub Action which is set up by this workflow file:

name: audit_alerts

on: 
  workflow_dispatch:
          
jobs:
  # JOB to run all deployments
  fetch:
    runs-on: ubuntu-latest

    outputs:
      alerts: ${{ steps.getlist.outputs.alerts }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Install jq
      run: sudo apt-get install jq

    - name: Install yq
      run: |
        sudo apt install snapd          
        sudo snap install yq

    - name: Get List
      id: getlist
      run: | 
        jsonlist=$(yq eval "keys" file-filters.yml --tojson)
        echo "::set-output name=alerts::$(echo $jsonlist)"
        
    - name: Print output
      run: echo ${{ steps.getlist.outputs.alerts }}

    - name: Print output fromJson
      run: echo ${{ fromJson(steps.getlist.outputs.alerts) }}

        
  audit:
    needs: fetch
    strategy:
      fail-fast: false
      matrix:
        alerts: ${{ fromJSON(needs.fetch.outputs.alerts) }}
    runs-on: ubuntu-latest
    env:
      version: '1.0.0'
      AZURE_STORAGE_CONNECTION_STRING: 'FileEndpoint=https://ncrsaassharedtemplates.file.core.windows.net/;SharedAccessSignature=sv=2019-10-10&ss=bfqt&srt=sco&sp=rwlacupx&se=2030-06-19T17:18:27Z&st=2020-06-19T09:18:27Z&spr=https&sig=oJEEWbshPqHXT4KHpeo62c726%2FZ%2FcUqKRU6KBe3yr78%3D'

    steps:

      - name: Checkout
        uses: actions/checkout@v2

      - name: Install jq
        run: sudo apt-get install jq

      - name: Install yq
        run: |
          sudo apt install snapd          
          sudo snap install yq

      - name: Install jsonlint
        run: sudo apt-get install python3-demjson

      - name: Set variables
        run: | 
          echo $MATRIX_CONTEXT
          alerts=$(echo $MATRIX_CONTEXT | jq -r '.alerts')
          echo "PRODUCT=$(cut -d'_' -f1 <<<"$alerts")" >> $GITHUB_ENV
          echo "ENVKEY=$(cut -d'_' -f2 <<<"$alerts")" >> $GITHUB_ENV
          echo "LEVEL=$(cut -d'_' -f3 <<<"$alerts")" >> $GITHUB_ENV
          echo "COMPONENT=$(cut -d'_' -f4 <<<"$alerts")" >> $GITHUB_ENV
          echo "RESOURCEGROUP=$(yq eval .$alerts.[].resourcegroup file-filters.yml | grep -v '^null$')" >> $GITHUB_ENV
          echo "SUBSCRIPTION_NAME=$(yq eval .$alerts.[].subscription file-filters.yml | grep -v '^null$')" >> $GITHUB_ENV
        env:
          MATRIX_CONTEXT: ${{ toJSON(matrix) }}

      - name: Lint Json files
        run: | 
          for file in ${{ env.PRODUCT }}/${{ env.ENVKEY }}/${{ env.LEVEL }}/${{ env.COMPONENT }}/alerts/*.json ; do jsonlint ${file} ; done
          for file in ${{ env.PRODUCT }}/${{ env.ENVKEY }}/${{ env.LEVEL }}/${{ env.COMPONENT }}/*.json ; do jsonlint ${file} ; done

      - name: AZ login
        run: az login --service-principal -u ${{ secrets.AZ_AD_TERRAFORM_DEPLOYMENT_APP_ID }} -p ${{ secrets.AZ_AD_TERRAFORM_DEPLOYMENT_CLIENT_SECRET }} --tenant ${{ secrets.AZ_AD_TERRAFORM_DEPLOYMENT_TENANT_ID }}

      - name: Get Subscription ID
        run: echo "SUBSCRIPTION=$(az account show --subscription "${{ env.SUBSCRIPTION_NAME}}" | jq -r '.id')" >> $GITHUB_ENV

      - name: Azure alerts audit
        run: | 
          az config set extension.use_dynamic_install=yes_without_prompt
          az monitor scheduled-query list --debug --subscription ${{ env.SUBSCRIPTION}} -g ${{ env.RESOURCEGROUP }}

Activity

  1. ghost added
    needs-triageThis is a new issue that needs to be triaged to the appropriate team.
    on Jun 18, 2021
  2. ghost added
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on Jun 18, 2021
  3. ghost removed
    needs-triageThis is a new issue that needs to be triaged to the appropriate team.
    on Jun 18, 2021
  4. removed
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on Jun 18, 2021
  5. added this to the S189 milestone on Jun 18, 2021
  6. yonzhan commented on Jun 18, 2021

    @yonzhan
    Collaborator

    monitor

  7. kairu-ms commented on Jun 21, 2021

    @kairu-ms
    Contributor

    Thanks for your feedback. After communicate with service team, that's because they are changing the response schema of 2021-02-01-preview version API. I will downgrade api version to 2020-05-01-preview in next release asap.

  8. kairu-ms commented on Jun 22, 2021

    @kairu-ms
    Contributor

    Fixed in 0.3.1, please update extension by command

    az extension update --name scheduled-query
  9. pp185214 commented on Jun 23, 2021

    @pp185214
    Author

    I can confirm that now it works fine. Thanks a lot for help. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Monitoraz monitorp1_e1priority=1 emergency=1

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions