Rest/SDK - how to get diagnostics settings for few NSGs in a bulk?

Revital Blum 40 Reputation points
2025-04-29T04:59:41.4633333+00:00

I get a list of NSG on a subscription using:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups?api-version=2024-05-01

How do I get the diagnostic setting for each NSG in one bulk? Only way I found is fetching it one by one with NSG id using rest/sdk

(I specifically want to fetch NetworkSecurityGroupRuleCounter information if defined )

I tried using resource graph but I'm not getting diagnostic settings information.

I don't want to define and use log analytics workspace

Any other option? even knowing which NSGs has diagnostic settings (or NetworkSecurityGroupRuleCounter ) can save me some redundant calls...

Azure Network Watcher
Azure Network Watcher
An Azure service that is used to monitor, diagnose, and gain insights into network performance and health.
187 questions
0 comments No comments
{count} votes

Accepted answer
  1. Stanislav Zhelyazkov 27,556 Reputation points MVP
    2025-04-29T05:47:30.3166667+00:00

    Hi,

    Unfortunately there is no other way. Diagnostic settings is indeed not available in ARG. This is due to being extension resource that requires additional work to be available there. The API also does not have functionality to list such diagnostic settings for specific subscription or even resource group. So the only way to do it is by querying it for each resource.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.