首页 > 解决方案 > 在 Azure Resource Graph 中查询资源子类型

问题描述

我正在尝试使用 Azure Policy 的资源图查询事件中心防火墙 IP 规则。我目前使用以下防火墙 IP 规则配置了一个事件中心。

{
        "type": "Microsoft.EventHub/namespaces/ipfilterrules",
        "apiVersion": "2018-01-01-preview",
        "name": "[concat(parameters('namespaces_myeventhub_name'), '/e51110a0-c074-43b3-85b7-b43e2eab4d9b')]",
        "location": "West US 2",
        "dependsOn": [
            "[resourceId('Microsoft.EventHub/namespaces', parameters('namespaces_myeventhub_name'))]"
        ],
        "properties": {
            "ipMask": "47.xxx.xxx.xxx",
            "action": "Accept",
            "filterName": "e51110a0-c074-43b3-85b7-b43e2eax4d9b"
        }
    }

查询

"where type =~ 'Microsoft.EventHub/namespaces'"

将在没有任何防火墙 IP 规则信息的情况下显示我的事件中心。此外还有一个查询

where type =~ 'Microsoft.EventHub/namespaces/ipfilterrules'

什么都不返回。我希望能够使用资源图查询这些信息,并最终针对这些属性编写 Azure 策略。我使用以下信息搜索了可能的别名

"where type =~ 'Microsoft.EventHub/namespaces' | limit 1 | project aliases"

但它返回的列表不包含事件中心的防火墙 IP 规则信息。这似乎是资源图中应该提供的基本信息......我错过了什么?

标签: azureazure-eventhubazure-policy

解决方案


经过测试,遗憾的是,只能通过 Azure Resource Graph API 查询事件中心命名空间的级别,不能直接通过 Azure Resource Graph 查询 ipfilterrules,请参考以下解决方案作为解决方法:

1:查询所有订阅下的事件中心命名空间 例如: https: //management.azure.com/subscriptions/ /providers/Microsoft.EventHub/namespaces?api-version=2018-01-01-preview

2:查询事件中心命名空间下的所有ipfilterrules,并在你的程序中一一过滤ipfilterrules。例如 https://management.azure.com/subscriptions/ /resourceGroups/ericm/providers/Microsoft.EventHub/namespaces//ipfilterrules?api-version=2018-01-01-preview

参考: https ://github.com/Azure/azure-rest-api-specs/blob/master/specification/eventhub/resource-manager/Microsoft.EventHub/preview/2018-01-01-preview/examples/NameSpaces/ IPFilterRule/EHNameSpaceIPFilterRuleListAll.json

希望对您的关心有所帮助。


推荐阅读