具有多个动态标记筛选器的 Azure 资源管理器查询

标签 azure azure-resource-manager cost-management azure-monitor-workbooks

我正在尝试查询 Azure 成本管理 API,并且希望能够根据 2 种不同类型的资源标签来筛选结果,但我无法确定格式。我可以让单个标签过滤器正常工作,但我对多个标签的格式空白。有人可以捐出 2 美分吗?

工作单个过滤器查询:

{
    "type": "Usage",
    "timeframe": "{TimeFrame}",
    "dataset": {
        "granularity": "None",
        "filter": {
            "tags": {
                    "name": "Environment",
                    "operator": "In",
                    "values": [
                        {Environment}
                    ]
                }
        },
        "aggregation": {
            "totalCost": {
                "name": "PreTaxCost",
                "function": "Sum"
            }
        },
        "grouping": [
            {
                "type": "Dimension",
                "name": "{Aggregation}"
            }
        ]
    }
}

我尝试添加多个过滤器:

{
    "type": "Usage",
    "timeframe": "{TimeFrame}",
    "dataset": {
        "granularity": "None",
        "filter": {
            "tags": [
                {
                    "name": "Environment",
                    "operator": "In",
                    "values": [
                        {Environment}
                    ]
                },
                {
                    "name": "Location",
                    "operator": "In",
                    "values": [
                        {Location}
                    ]
                }
            ]
        },
        "aggregation": {
            "totalCost": {
                "name": "PreTaxCost",
                "function": "Sum"
            }
        },
        "grouping": [
            {
                "type": "Dimension",
                "name": "{Aggregation}"
            }
        ]
    }
}

我对 Azure 很陌生,所以请不要太严厉地 mock 我,哈哈。

感谢所有看过我的问题的人,即使您没有给我答案,我也非常感激。

最佳答案

我的参数设置方式存在问题,导致查询错误。以下是具有用于过滤的多个标签属性的工作代码:

{
"type": "Usage",
"timeframe": "{TimeFrame}",
"dataset": {
    "granularity": "None",
    "filter": {
        "and": [
            {
                "tags": {
                    "name": "Location",
                    "operator": "In",
                    "values": [{LocationTag}]
                }
            },
            {
                "tags": {
                    "name": "Environment",
                    "operator": "In",
                    "Values": [{EnvironmentTag}]
                }
            },
            {
                "tags": {
                    "name": "Integrated-System",
                    "operator": "In",
                    "Values": [{IntegratedSystemTag}]
                }
            }
        ]
    },
    "aggregation": {
        "totalCost": {
            "name": "PreTaxCost",
            "function": "Sum"
        }
    },
    "grouping": [
        {
            "type": "Dimension",
            "name": "{Aggregation}"
        }
    ]
}

}

关于具有多个动态标记筛选器的 Azure 资源管理器查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72492809/

相关文章:

Azure blob 容器 listBlobs 用于在 java 中获取具有特定扩展名的文件

azure - 错误请求 : The document creation or update failed because of invalid reference

Azure函数+ARM : merge app settings with current settings

amazon-web-services - 如何使用 AWS CLI 获取每日成本

azure - 如何检索 Azure 复制任务名称?

Azure KeyVault : SPN KeyVault Access Denied

Azure REST 服务成本

MySQL 整个时间内按类别的成本

json - Microsoft LUIS - 话语和实体中的 startPos 和 EndPos

azure - 在内部模式下部署多个 API 管理阶段/生命周期时,是否需要单独的子网?