如何使用 Azure CLI 筛选 JMESPath 中的元素数组
How to filter array of elements in JMESPath with Azure CLI
我是 JMESPath 解析的新手。
az network lb inbound-nat-rule list --resource-group MYRG --lb-name MYLB
返回低于输出,我只想在响应中过滤 backendIpConfiguration.id
和 backendPort
。
下面的响应包含元素数组。
[
{
"backendIpConfiguration": {
"applicationGatewayBackendAddressPools": null,
"applicationSecurityGroups": null,
"etag": null,
"gatewayLoadBalancer": null,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"loadBalancerBackendAddressPools": null,
"loadBalancerInboundNatRules": null,
"name": null,
"primary": null,
"privateIpAddress": null,
"privateIpAddressVersion": null,
"privateIpAllocationMethod": null,
"privateLinkConnectionProperties": null,
"provisioningState": null,
"publicIpAddress": null,
"resourceGroup": "MYRG01",
"subnet": null,
"type": null,
"virtualNetworkTaps": null
},
"backendPort": 1367,
"enableFloatingIp": false,
"enableTcpReset": false,
"etag": "W/\"XXXXX-1173-49ad-8d1f-40347c00d88a\"",
"frontendIpConfiguration": {
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"resourceGroup": "MYRG01"
},
"frontendPort": 1367,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"idleTimeoutInMinutes": 5,
"name": "rule1",
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "MYRG01",
"type": "Microsoft.Network/loadBalancers/inboundNatRules"
},
{
"backendIpConfiguration": {
"applicationGatewayBackendAddressPools": null,
"applicationSecurityGroups": null,
"etag": null,
"gatewayLoadBalancer": null,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"loadBalancerBackendAddressPools": null,
"loadBalancerInboundNatRules": null,
"name": null,
"primary": null,
"privateIpAddress": null,
"privateIpAddressVersion": null,
"privateIpAllocationMethod": null,
"privateLinkConnectionProperties": null,
"provisioningState": null,
"publicIpAddress": null,
"resourceGroup": "MYRG02",
"subnet": null,
"type": null,
"virtualNetworkTaps": null
},
"backendPort": 3006,
"enableFloatingIp": false,
"enableTcpReset": false,
"etag": "W/\"XXXX-1173-49ad-8d1f-40347c00d88a\"",
"frontendIpConfiguration": {
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"resourceGroup": "MYRG02"
},
"frontendPort": 3006,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"idleTimeoutInMinutes": 5,
"name": "rule2",
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "MYRG02",
"type": "Microsoft.Network/loadBalancers/inboundNatRules"
}
]
JMESPath 中的过滤非常简单,filters and multiselect hashes 的文档非常简单明了。
在这里,一个简单的查询如下:
[].{backendIpConfigurationId: backendIpConfiguration.id, backendPort: backendPort}
会给你过滤后的 JSON:
[
{
"backendIpConfigurationId": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"backendPort": 1367
},
{
"backendIpConfigurationId": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"backendPort": 3006
}
]
只包含您要查找的信息。
我是 JMESPath 解析的新手。
az network lb inbound-nat-rule list --resource-group MYRG --lb-name MYLB
返回低于输出,我只想在响应中过滤 backendIpConfiguration.id
和 backendPort
。
下面的响应包含元素数组。
[
{
"backendIpConfiguration": {
"applicationGatewayBackendAddressPools": null,
"applicationSecurityGroups": null,
"etag": null,
"gatewayLoadBalancer": null,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"loadBalancerBackendAddressPools": null,
"loadBalancerInboundNatRules": null,
"name": null,
"primary": null,
"privateIpAddress": null,
"privateIpAddressVersion": null,
"privateIpAllocationMethod": null,
"privateLinkConnectionProperties": null,
"provisioningState": null,
"publicIpAddress": null,
"resourceGroup": "MYRG01",
"subnet": null,
"type": null,
"virtualNetworkTaps": null
},
"backendPort": 1367,
"enableFloatingIp": false,
"enableTcpReset": false,
"etag": "W/\"XXXXX-1173-49ad-8d1f-40347c00d88a\"",
"frontendIpConfiguration": {
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"resourceGroup": "MYRG01"
},
"frontendPort": 1367,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"idleTimeoutInMinutes": 5,
"name": "rule1",
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "MYRG01",
"type": "Microsoft.Network/loadBalancers/inboundNatRules"
},
{
"backendIpConfiguration": {
"applicationGatewayBackendAddressPools": null,
"applicationSecurityGroups": null,
"etag": null,
"gatewayLoadBalancer": null,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"loadBalancerBackendAddressPools": null,
"loadBalancerInboundNatRules": null,
"name": null,
"primary": null,
"privateIpAddress": null,
"privateIpAddressVersion": null,
"privateIpAllocationMethod": null,
"privateLinkConnectionProperties": null,
"provisioningState": null,
"publicIpAddress": null,
"resourceGroup": "MYRG02",
"subnet": null,
"type": null,
"virtualNetworkTaps": null
},
"backendPort": 3006,
"enableFloatingIp": false,
"enableTcpReset": false,
"etag": "W/\"XXXX-1173-49ad-8d1f-40347c00d88a\"",
"frontendIpConfiguration": {
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"resourceGroup": "MYRG02"
},
"frontendPort": 3006,
"id": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"idleTimeoutInMinutes": 5,
"name": "rule2",
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "MYRG02",
"type": "Microsoft.Network/loadBalancers/inboundNatRules"
}
]
JMESPath 中的过滤非常简单,filters and multiselect hashes 的文档非常简单明了。
在这里,一个简单的查询如下:
[].{backendIpConfigurationId: backendIpConfiguration.id, backendPort: backendPort}
会给你过滤后的 JSON:
[
{
"backendIpConfigurationId": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"backendPort": 1367
},
{
"backendIpConfigurationId": "/subscriptions/XXXX/XXX/XXX/providers/Microsoft.Network/networkInterfaces/XXX/ipConfigurations/XXXX",
"backendPort": 3006
}
]
只包含您要查找的信息。