简体   繁体   English

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

[英]Azure Resource Manager Query with multiple dynamic tag filters

I'm trying to query the Azure Cost Management API and I want to be able to filter the results based off of 2 different types of resource tags but I am having trouble figuring out the format.我正在尝试查询 Azure 成本管理 API,我希望能够根据 2 种不同类型的资源标签过滤结果,但我无法确定格式。 I can get the single tag filter working, but I'm blanking on the format for multiple.我可以让单个标签过滤器正常工作,但我对多个标签的格式一无所知。 Can anyone throw in their 2 cents?任何人都可以投入他们的 2 美分吗?

Working single filter query:工作单个过滤器查询:

{
    "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}"
            }
        ]
    }
}

My attempt at adding more than one filter:我尝试添加多个过滤器:

{
    "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}"
            }
        ]
    }
}

I am very new to Azure so please don't roast me too hard lol.我对 Azure 很陌生,所以请不要把我烤得太厉害,哈哈。

Thank you to everyone who took a look at my question, much appreciated even if you don't have an answer for me.感谢所有看过我问题的人,即使您没有我的答案,也非常感谢。

There was an issue with the way my parameters were set causing a bad query.我的参数设置方式存在问题,导致查询错误。 Here is the working code with multiple tag attributes for filtering:这是具有用于过滤的多个标签属性的工作代码:

{
"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}"
        }
    ]
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM