question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MonitorClient.diagnosticSettings.list(resource)` returns empty when it should return settings

See original GitHub issue
  • Package Name: @azure/arm-monitor
  • Package Version: 7.0.0
  • Operating system: MacOS
  • nodejs
    • version: v16.15.0
  • browser
    • name/version:
  • typescript
    • version: v10.7.0
  • Is the bug related to documentation in

Describe the bug I have created a ‘Diagnostic setting’ in the Azure Web Console for Key Vault. When I run both the Azure CLI and the corresponding MonitorClient.diagnosticSettings.list(resource) in this package I get the response:

{"value":[]}}

When I hit the same endpoint with the a new API version I get a response: az rest --method get --url "https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.KeyVault/vaults/<KEY_VAULT_NAME>/providers/Microsoft.Insights/diagnosticSettings?api-version=2021-05-01-preview"

I suspect it’s related to the same API issue here: https://github.com/Azure/azure-powershell/issues/18334

To Reproduce Steps to reproduce the behavior:

  1. Create a key vault
  2. On the ‘Monitor’ page on the web console create a diagnostic setting for the key vault
  3. Call the list method of the diagnosticSettings interface from the MonitorClient and pass in the resource ID of the previously created

Expected behavior It should return the diagnostic setting of the key vault

Screenshots If applicable, add screenshots to help explain your problem. Screen Shot 2022-06-22 at 1 40 06 pm Screen Shot 2022-06-22 at 1 43 42 pm

Additional context if we could pass in api-version to our MonitorClient client then i think that would be able to fix this problem?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
tadeleshcommented, Aug 1, 2022

@tadelesh so how should we override the API version in GO ? just fork the relevant classes of diagnostics ?

@itamarazulay-wiz Unfortunately, we do not give an easy way to set api-version in Go SDK. Besides changing the source code directly, you could accomplish it by add a special policy to the diagnostics client. Something like the following:

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)

func main() {
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		log.Fatalf("failed to obtain a credential: %v", err)
	}
	ctx := context.Background()
	client, err := armmonitor.NewDiagnosticSettingsClient(cred, &arm.ClientOptions{
		ClientOptions: policy.ClientOptions{
			PerCallPolicies: []policy.Policy{
				NewSetApiVersionPolicy("2021-05-01-preview"),
			},
		},
	})
	if err != nil {
		log.Fatalf("%+v", err)
	}
	result, err := client.List(ctx, "<resourceURI>", nil)
	if err != nil {
		log.Fatalf("%+v", err)
	}
	for _, item := range result.Value {
		fmt.Println(item)
	}
}

type setApiVersionPolicy struct {
	newApiVersion   string
}

func NewSetApiVersionPolicy(newApiVersion string) policy.Policy {
	return &setApiVersionPolicy{newApiVersion: newApiVersion}
}

func (p *setApiVersionPolicy) Do(req *policy.Request) (resp *http.Response, err error) {
	query := req.Raw().URL.Query()
	query.Set("api-version", p.newApiVersion)
	req.Raw().URL.RawQuery = query.Encode()
	return req.Next()
}
1reaction
qiaozhacommented, Aug 3, 2022

@edmundcong @itamarazulay-wiz I will close this issue now as the JS SDK issue should have been resolved . Feel free to open a new issue in Go SDK repo if you still want to discuss this. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

az monitor diagnostic-settings | Microsoft Learn
List the diagnostic settings categories for the specified resource. ... cls: A custom type or function that will be passed the direct response:return: ......
Read more >
Get all Diagnostic Settings from Azure using API
What you would need to do is list down all the resources in your SUbscription and then for each resource you will need...
Read more >
Enable Diagnostic Logs for the Supported Resources
02 The command output should return the requested resource identifiers (IDs): ... If the monitor diagnostic-settings list command output returns an empty ......
Read more >
Azure Diagnostic Settings “category Group” argument is not ...
resource "azurerm_logic_app_workflow" "workflow" { name = "test-secops-workflow" location = azurerm_resource_group.rg.location ...
Read more >
Finding Diagnostic Settings Configuration for Azure ...
Current destinations include Log Analytics workspace, Event Hubs, and Azure Storage. The platform logs include Azure resources (resource logs), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found